Reputation: 1
How do I fix this site speed recommendation with wordpress to remove query strings from static resources.
I have some Resources with a "?x54532" on the final of the link including images, js, css....
des/css/dashicons.min.css?x54532'
wp-includes/css/admin-bar.min.css?x54532
wp-content/uploads/2017/12/favicon.png?x54532"
I have 131 links with that query string"?x54532"
Upvotes: 0
Views: 434
Reputation: 830
// Remove Query String
function nerodev_remove_query_string($src) {
$parts = explode('?ver=', $src);
return $parts[0];
}
add_filter('script_loader_src', 'nerodev_remove_query_string', 15, 1);
add_filter('style_loader_src', 'nerodev_remove_query_string', 15, 1);
Source is here
Upvotes: 0
Reputation: 557
The advice "Remove query strings from static resources" is no longer relevant.
The advice originally came from Google PageSpeed but they dropped the recommendation in 2014. By that point, GTMetrix and Pingdom had already adopted all the PageSpeed recommendations and they've not yet updated their testing criteria to match the new PageSpeed recommendations.
You can go direct to Google PageSpeed to test your website here:
https://developers.google.com/speed/pagespeed/insights/
You will notice that "Remove query strings from static resources" is not a PageSpeed recommendation. The reason Google dropped it is because proxy servers like Squid have been caching static resources with query strings for about a decade already.
There are other good reasons why you should ignore the query string advice, not least that GTMetrix doesn't score your website down even with a 0% score:
https://sirv.com/help/resources/remove-query-strings-from-static-resources/
Instead, prioritise your time to fix the important PageSpeed recommendations that will make your pages load faster.
Upvotes: 1
Reputation: 935
Place this in your theme's functions.php
file or create a plugin file.
function remove_script_style_version( $src ) {
if ( strpos( $src, 'ver=' ) ) {
$src = remove_query_arg( 'ver', $src );
}
if ( strpos( $src, 'x54532' ) ) {
$src = remove_query_arg( 'x54532', $src );
}
return $src;
}
add_filter( 'style_loader_src', 'remove_script_style_version', 1000 );
add_filter( 'script_loader_src', 'remove_script_style_version', 1000 );
Upvotes: 0