Removing Query Strings from Static Resources
If you are a WordPress user, removing of query strings from static resources does matter in the website’s performance. When I was developing my blog’s theme I faced the same issues. In order to remove the query strings from the static resources we can write a small piece of javascript or write a simple function in php. I would prefer writing the php code in the functions.php file to remove query strings from static resources.
Are you confused? What does query strings in url mean? Just look at the urls of my website shown below.
I guess you might understood what are query strings in the url, just the parameters we are passing after the question mark in the url are called as the query strings.
Why Query Strings from Static Resources must be removed?
We should remove all the query strings from static resources for the better caching at proxies. Caching is one of the important factor in terms of website’s performance. Resources with a “?” in the URL are not cached by some proxy caching servers. Let’s see how to remove all the query strings.
//remove query strings from static resources
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 );
```
Thats all you should add into your functions.php file for removing query strings from static resources and make proxy caching better. All the best. Happy Learning!
Enjoy Reading This Article?
Here are some more articles you might like to read next: