Serve static assets with an efficient cache policy - Help Needed

VibroHeavenUK

Power Member
Joined
Apr 18, 2021
Messages
604
Reaction score
333
Hi,

I have run various SEO software on my site and they all recommend 'Serve static assets with an efficient cache policy'.

I'm using WP Rocket and have the Cache Lifespan set to 365 days but still get the same problem, After searching on Google, the WP Rocket page recommended using the 'Leverage Browser Caching' plugin which basically rewrites the .htacess file and I get a warning that the plugin is not compatable with WP Rocket!!!

After a scan today, I still have 1,700 urls that have a problem, 300 are fine. I'm using an Apache server as Nginx requires a different solution.

Does anyone have any ideas on how to solve this please?
 
Also remove the version from CSS and JS files in WordPress. Almost all CSS and js files in WordPress have the WordPress version number attached to the file names or included in the query string. Because the file is viewed as dynamic, having a query string in the URL does not cache it.

Code:
<?php
// Remove version from scripts and styles
function cxc_remove_css_js_version_callback( $src ) {
    if( $src && strpos( $src, '?ver=' ) ){
        $src = remove_query_arg( 'ver', $src );
    }
    return $src;
}

add_filter( 'style_loader_src', 'cxc_remove_css_js_version_callback', 9999 );
add_filter( 'script_loader_src', 'cxc_remove_css_js_version_callback', 9999 );

// Remove version from head
remove_action('wp_head', 'wp_generator');

// Remove version from rss
add_filter('the_generator', '__return_empty_string');
?>
 
Also remove the version from CSS and JS files in WordPress. Almost all CSS and js files in WordPress have the WordPress version number attached to the file names or included in the query string. Because the file is viewed as dynamic, having a query string in the URL does not cache it.

Code:
<?php
// Remove version from scripts and styles
function cxc_remove_css_js_version_callback( $src ) {
    if( $src && strpos( $src, '?ver=' ) ){
        $src = remove_query_arg( 'ver', $src );
    }
    return $src;
}

add_filter( 'style_loader_src', 'cxc_remove_css_js_version_callback', 9999 );
add_filter( 'script_loader_src', 'cxc_remove_css_js_version_callback', 9999 );

// Remove version from head
remove_action('wp_head', 'wp_generator');

// Remove version from rss
add_filter('the_generator', '__return_empty_string');
?>

Thank you, but where would I add this? Would I be able to add it too 'Code Snippets'?
 
Back
Top