If you’ve been working with WordPress for a while, I’ll bet you’ve noticed the query string attached to each .js and .css file loaded by your site. (For those not familiar with query strings, they are all the jargon appended to your files when enqueued, for example &ver=1.1 or something siliar.)
This happens because whenever WordPress includes a script or a style sheet by using the wp_enqueue_style or wp_enqueue_script function it will include a query string for the version of the file. Both of these functions have a version parameter which allows the developer to append any version number that they want to the query string, if the version number doesn’t exist in the function then WordPress will append the WordPress version to the end of the URLs.
This is a problem as many proxies will not cache the resources if it has a query string in the URL. Which can cause the site to not function or display properly for certain users, or it may require extra HTTP requests to retrieve the latest versions etc. In short, leaving query strings on static resources will slow your site down (not by a whole lot, but it will, and those of us who are speed conscious understand every millisecond counts on the web).
There are a whole lot of plugins in the repository that claim to remove query strings and all sorts of jargon from your enqueued files. However, it’s quite simple to remove these query strings without the use of a plugin. All we need to do, is use some core PHP functionality to remove the unwanted ver number from our file. Like so:
Add the above code to your functions.php file and you are all set! You may need to make adjustments and ad extra if() statements to remove all version numbers. Of course, this function can be used to remove any parameters from the script tag.