Remove Version Query String From Static JS And CSS Files

[ad_1]

A website owner should always be trying to improve the speed of their website as much as possible. When you analyze your page using any page speed analyzer such as Page Speed, YSlow or Pingdom, you are very likely to see suggestions to remove query strings from static resources, such as Stylesheets and JavaScript files. This is a problem as many proxies will not cache the resources if it has a query string in the URL. A tip on the Google best practice pages is to remove all query strings from your static resources to enable proxy caching of the file. So in this article I will show you how you can easily remove version query string from static scripts and stylesheets.

Most of the stylesheets and JavaScript files added by WordPress plugins and themes usually have version query string (?ver=) in their URL. And we want to remove version query string from these static resources to make our pages and static resource to cache so that the pages can load faster. There are a couple of plugins in WordPress respiratory that does this job but this is an easy enough task to use plugin.

Just paste this following WordPress snippet in your theme’s functions.php file to remove version query string from static scripts and stylesheets resources. Once you are done adding this snippet in your theme, head back to analyze your page again and notice the difference.

// remove version query string from scripts and stylesheets
function wcs_remove_script_styles_version( $src ){
    return remove_query_arg( 'ver', $src );
}
add_filter( 'script_loader_src', 'wcs_remove_script_styles_version' );
add_filter( 'style_loader_src', 'wcs_remove_script_styles_version' );
[ad_2]

Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads