• Hello guys, I have at last made up my mind to enable preload, it’s still not finished yet but it seems that it slows down things in pagespeed (ofc testing the homepage link https://medicalfa.gr) if dropped from 90% to 82% which is a huge drop don’t you think? Should I wait for preload to end and retest or shut it down entirely? I have set the preload expiration to 0.

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter johndos

    (@johndos)

    So today I noticed that not only preload wasn’t done by morning but it had stopped and I had to start it again. Then it has been at least an hour and it’s stuck at

    Currently caching from post 0 to 100.

    Page last cached: 12 https://medicalfa.gr/product/buratto-rediab/

    what could be the cause of that?

    It could be an issue related to cron. Did you try to set “server process” which runs wp-cron.php periodically?

    More details related to cron:
    https://kinsta.com/knowledgebase/disable-wp-cron/
    https://www.hosteurope.de/faq/webserver-dedicated/allgemeines-webserver/cronjob-webserver/

    Please enable debugging in WP and check debug.log for possible PHP errors/warnings. Also, it’ll be helpful to enable debugging in WP SuperCache (Settings > WP Super Cache > Debug ). WPSC log will show details for preload process.

    Thread Starter johndos

    (@johndos)

    Hello Sasa I have also forgot to mention that I have the HTTP/2 Server Push plugin active, could it mess around with the preload?

    The plugin HTTP/2 Server Push adds some details in Link header. It can’t work if you set “Expert” cache delivery method because Rewrite Rules can’t send custom headers. You should enable “Simple” method and set option “Cache HTTP headers with page content”. You can find other topics (and issues) here related to it. Also, I think that you need to install development version of WPSC because it contains PR 641.

    Preload should work (but headers aren’t cached – I just checked your website). Please check server logs (PHP and Apache) and enable debugging. WPSC debug log shows a few lines for each URL. An example:

    11:46:02 31806 /wp-cron.php wp_cache_get_cookies_values: return: 
    11:46:02 31806 /wp-cron.php In WP Cache Phase 2
    11:46:02 31806 /wp-cron.php Setting up WordPress actions
    11:46:02 31806 /wp-cron.php Not caching wp-admin requests.
    11:46:07 31806 /wp-cron.php wp_cron_preload_cache: doing taxonomy preload.
    11:46:07 31806 /wp-cron.php wp_cron_preload_cache: delete .....
    11:46:08 31806 /wp-cron.php wp_cron_preload_cache: fetched .....
    

    It’s huge log with a lot of details.

    Thread Starter johndos

    (@johndos)

    So you think I should enable the Cache HTTP headers with page content.? Won’t that slow down the website as it uses PHP file delivery?

    Expert mode saves resources, but Simple (PHP) method loads minimal number of files (minimal WP core without theme and plugins) – it’s little difference (on PHP-FPM) if you don’t have a lot of concurrent requests. Also, “Cache HTTP headers” will create wp-cache file instead of super cache files (It’s possible that will create multiple wp-cache files instead of single index.html/index.html.gz depends on request). So, it’s hard to decide. Personally, I use custom rules in .htaccess (Expert method) for maximal performance.

    Related to “Link” header, I’ll recommend to you deactivate plugin and add minimal number of styles/scripts in the header (huge header could have performance impacts). You could use action template_redirect and PHP function header for it. If preload works as should, then you don’t need it (because it’s important only when there aren’t cache files).

    You could add custom rules (in .htaccess before WPSC rules) for already cached files:

    # BEGIN Custom HTTP/2 headers for cached files
    <FilesMatch "\.(html|html.gz)$">
    Header add Link "</wp-content/themes/my-theme/style.css>; rel=preload; as=style"
    Header add Link "</wp-content/themes/my-theme/script.js>; rel=preload; as=script"
    </FilesMatch>
    # END Custom HTTP/2 headers for cached files
    

    I think that’s enough to add couple common files. Also, I’ve good experience with CDNJS – free CloudFlare library for scripts/styles. There are many benefits (it’s faster than regular CDN, some scripts could be already cached in browsers,…).

    Other issue (because your website is behind CF) could be short max-age in Cache-Control header. You could try to add custom WPSC_CACHE_CONTROL_HEADER in wp-config.php (maybe 3600s) if you don’t often change content on the website. More details – https://www.ads-software.com/support/topic/value-of-cache-control-max-age3-must-revalidate/

    Thread Starter johndos

    (@johndos)

    Thanks a lot! I will test it in the evening and let you know.

    Thread Starter johndos

    (@johndos)

    So I have installed the dev version of WPSC and have added the WPSC_CACHE_CONTROL_HEADER set to 3600. I haven’t touched the .htaccess yet as I am not sure of what to load and what not. Thus I didn’t disable the plugin for HTTP/2. But I have already switched to simple (to be honest I haven’t changed it since I installed the plugin). Also I have enabled the Cache HTTP headers with page content and just now cleared cache from CF, FVM and WPSC.
    If you need to see the debug logs I am happy to send them.

    If you set “Cache HTTP headers” then you need to apply changes PR 641 (it still isn’t merged in development version of WPSC) because current WPSC (1.6.4) doesn’t support multiple headers with same name. Also, WPSC doesn’t use the constant WPSC_CACHE_CONTROL_HEADER in this case (because “Cache HTTP headers” only stores headers without changing them).

    I’ll try to write more details tomorrow.

    Thread Starter johndos

    (@johndos)

    Alright thank you a lot, really man thank you, also for the cdnjs, should I disable photon and add cdnjs.cloudflare.com in the WPSC cdn support?
    For the PR641 I have edited the code, but only the first part on line 229 and 231-233 but the other part that needs to be deleted doesn’t exist in the code
    $headers[ $hdr_key ] = ltrim( substr( $hdr, $ptr + 1 ) );
    So I didn’t add the later part on 1448 – 1454.

    • This reply was modified 5 years, 11 months ago by johndos.
    • This reply was modified 5 years, 11 months ago by johndos.

    It isn’t so simple. You need to dequeue scripts/style and enqueue CDNJS URLs. Basically, something like this:

    wp_dequeue_style( 'font-awesome' );
    wp_deregister_style( 'font-awesome' );
    wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/css/all.min.css', array(), NULL, 'all');  
    

    It’s better to use style_loader_src and script_loader_src to change source. I’ll try to provide better example if I find spare time.

    On this way, it’s possible to reduce number of requests to your domain, but it requires some time to find exact URLs on CDNJS. Also, you need to update these filters from time to time. Good thing is that version is hard-coded in path and browsers will quickly get new versions (it’s much better than query strings which is used by default in WP).

    PS: I think that you need to add lines 1448–1454 because this part of code will combine multiple headers into single header.

    • This reply was modified 5 years, 11 months ago by Sa?a.
    Thread Starter johndos

    (@johndos)

    I get what you mean, I have to add the dequeue/dereguster abd enqueue styles/js in functions.php after they are enqueued by the theme.

    so after the

    wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/vendors/font-awesome/css/font-awesome' . $min . '.css', '', '4.7.0' );

    I should add the

    wp_dequeue_style( 'font-awesome' );
    wp_deregister_style( 'font-awesome' );
    wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.1/css/all.min.css', array(), NULL, 'all');

    etc for each global CSS and JS

    and if it’s a script I should

    wp_dequeue_script( '' );
    wp_deregister_script( '' );
    wp_enqueue_script( 'js, cdnjs_url, $deps, $ver, $media );

    P.S. I have added the lines but it starts on line 1457 to 1463

    		if ( in_array( strtolower( $hdr_key ), $known_headers, true ) ) {
    			$hdr_val = ltrim( substr( $hdr, $ptr + 1 ) );
    			if ( ! empty( $headers[ $hdr_key ] ) ) {
    				$hdr_val = $headers[ $hdr_key ] . ', ' . $hdr_val;
    			}
    			$headers[ $hdr_key ] = $hdr_val;
    		}

    right after the

    	$headers = array();
    	if ( function_exists( 'apache_response_headers' ) ) {
    		$headers = apache_response_headers();
    	}
    	if ( empty( $headers ) && function_exists( 'headers_list' ) ) {
    		$headers = array();
    		foreach( headers_list() as $hdr ) {
    			$header_parts = explode( ':', $hdr, 2 );
    			$header_name  = isset( $header_parts[0] ) ? trim( $header_parts[0] ) : '';
    			$header_value = isset( $header_parts[1] ) ? trim( $header_parts[1] ) : '';
    
    			$headers[$header_name] = $header_value;
    		}
    	}
    
    	foreach( $headers as $key => $value ) {
    		if ( ! in_array( strtolower( $key ), $known_headers ) ) {
    			unset( $headers[ $key ] );
    		}
    	}
    
    	return $headers;
    }
    • This reply was modified 5 years, 11 months ago by johndos.
    • This reply was modified 5 years, 11 months ago by johndos.

    It’s little out of topic, but I’ll try to explain some details related to scripts/styles.

    You should create child theme (to preserve your changes in the update) and use action wp_enqueue_scripts (with higher priority) to dequeue/enqueue scripts/styles. An example from my functions.php (little modified) which removes multiple copies of font-awesome:

    add_action( 'wp_enqueue_scripts', function() {
    
            $font_awesome = false;
            if ( wp_style_is( 'yith-wcwl-font-awesome' ) || wp_style_is( 'essb-fontawsome' )) {
                    wp_dequeue_style( 'yith-wcwl-font-awesome' );
                    wp_dequeue_style( 'essb-fontawsome' );
                    $font_awesome = true;
            }
    
            if ( $font_awesome || wp_style_is( 'font-awesome' ) ) {
                    wp_dequeue_style( 'font-awesome' );
                    wp_deregister_style( 'font-awesome' );
                    wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css', array(), NULL, 'all' );
            }
    }, 1000 );
    

    If some script/style has dependencies then I recommend to you use script_loader_src or style_loader_src. An example (changes jquery-core and remove jquery-migrate):

    add_filter( 'script_loader_src', function( $src, $handle ) {
            if ( is_admin() ) {
                    return $src;
            }
    
            if ( $handle === 'jquery-core' ) {
                    $src = 'https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js';
            } elseif ( $handle === 'jquery-migrate' ) {
                    $src = false;
            }
    
            return $src;
    }, 1000, 2 );
    

    I hope that’s enough to you could handle it on proper way. If you use CDNJS for some scripts/styles then you should check that FVM doesn’t process them.

    I see other issue related to PR 641 because apache_response_headers can’t return multiple headers with same name and there was bug in this function (it was fixed in PR 618). Maybe you could download master repo from github as zip file, unpack it to your computer, rename wp-super-cache-master to wp-super-cache and upload it to your server. I’m using master repo on few production servers and I didn’t see issues for now.

    Thread Starter johndos

    (@johndos)

    Thank you very much for the explanation above. I will test it.

    I have downloaded the file from here in github, hopefully it’s the correct one.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘preload slows down my pagespeed’ is closed to new replies.