Feb, 2016
Why doesn’t Comet Cache remove query strings from static resources?
Many speed testing services such as Google PageSpeed and GTMetrix will reduce your overall score if you don't "Remove Query Strings From Static Resources". What these services don't consider, however, is that a dynamic site running a Content Management System (CMS) such as WordPress must use query strings for static resources to ensure that everything stays up-to-date.
This dependency on query strings is build right into the WordPress functions used by plugin and theme developers to load JavaScript files (wp_enqueue_script()
and CSS files (wp_enqueue_style()
): both include a Version Parameter, which allows the plugin or theme developer to specify the version number of the file being loaded. That version number then gets appended to the static resource link as a query string (e.g., theme-style.css?ver=1.5
).
If a plugin or theme developer chooses not to use this Version Parameter, WordPress will go ahead and add one on its own. See the following from the WordPress Codex regarding the Version Parameter:
String specifying the script version number, if it has one, which is concatenated to the end of the path as a query string. If no version is specified or set to false, then WordPress automatically adds a version number equal to the current version of WordPress you are running. If set to null no version is added. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the script.
Why is a version number necessary?
In a WordPress environment, you will be running many different plugins, each with its own version. You'll also be using a WordPress theme, which also has a specific version and will get updated from time to time.
When someone visits your website, all of the JavaScript and CSS files may be cached (stored), either in the visitors web browser or, if you're using the Comet Cache Static CDN Filters, by your CDN provider.
When you update WordPress, or when you update a WordPress theme or plugin, those cached JavaScript and CSS files will likely change. However, the only way to tell visitors' browsers and your CDN provider that the files have changed is to change the link to the files.
How do we change the link to each file without actually needing to change the names of the files every time something is updated? We do that by changing the version number at the end of the file, e.g., theme-style.css?ver=1.5
might become theme-style.css?ver=1.6
after a theme update. When we change the version number, we change the link to the file, which tells visiting web browsers and your CDN to fetch the newest copy of the file.
That ?ver=1.6
portion is the "Query String". If we removed that query string--as many speed testing services recommend--then your WordPress site wouldn't function properly. Your visitors would end up seeing old versions of your site!
It's for this reason that Comet Cache does not remove query strings from static resources--doing so would essentially break your WordPress site.