Easily remove query string from static resources : By default WordPress generates query strings for static resources like CSS,JavaScript and jQuery URL's.We are listing 2 amazing methods to remove query strings from static resources in WordPress by editing theme's functions.php file and W3 total cache settings.Resources with a “?” or “&” in the URL are not cached by most of the proxy servers and affects on page load time.The best solution is you must remove the query string from URL.
Remove Query Strings from static resources in WordPress
Pingdom, Google's page speed insights , Gtmetrix and Yahoo's Yslow recommends you to remove query string from static resources to speed up WordPress blog.As we discussed above by default WordPress will generate query strings to show the version number of static resources. WordPress theme, Plugin contains CSS, JavaScript and jQuery files, for each file WordPress produces a version number.
You may have experienced in WordPress with "?" query string from URL.To remove query strings from static resources in WordPress, add the following code snippet to your wordpress theme's functions.php file.
Go to Appearcence > Editor > Functions.php, and paste the following code at the end of your file.
function _remove_script_version( $src ){
$parts = explode( '?', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
Note: It's not possible to remove the query string from Google Analytics and Adsense because these ads are served from their own host.You can't do anything about it.
Remove Query String from static resources with W3 Total Cache plugin
It can also be done with W3 total cache plugin.Just follow the tutorial to remove query string from static resources URL with the best W3 total cache settings.
Go to Performance > Browser Cache and look for Prevent caching of objects after settings change.This can be found under General and CSS/JS files section.Uncheck this option to completely remove query strings from static resources.if you enable this option,then W3 total cache will generate a new query and appended to objects allowing the new policy to be applied.
General :Uncheck-Prevent caching of objects after settings change.
CSS/JS : Uncheck-Prevent caching of objects after settings change.
That's it, if you found any difficulty to remove query strings from your WordPress site, let me know.