Use code PERFMATTERS for an additional 10% off!

How to Remove Query Strings From Static Resources

Query strings are versions that are appended on the ends of assets (CSS, JS), such as edd.min.css?ver=2.7.9. Sometimes proxy servers and older CDNs might have trouble caching these. You might also see a warning about query strings showing up in your speed tests. You can safely remove query strings from static resources and it won’t harm your site. It can only help it.

Removing Query Strings

Here is an example on our site before removing query strings.

query strings on static resources
Query strings on static resources

In the perfmatters plugin you can easily remove query strings from static resources by enabling the “Remove Query Strings” option.

Remove query strings with perfmatters plugin
Remove query strings with perfmatters plugin

And here is an example after removing them.

no query strings on static resources
No query strings on static resources

Query Strings Aren’t Being Removed?

Sometimes plugin or theme developers don’t properly enqueue their files or hard code the reference to the version number. This disables the ability to check with a WordPress hook to properly strip out the query strings. This is not a problem with the perfmatters plugin, but it means you will need to edit their file to remove the query strings manually.

Example 1 – Social Warfare Plugin

One example is the Social Warfare WordPress plugin. You might see this file with a query string: wp-content/plugins/social-warfare/fonts/sw-icon-font.woff?ver=2.2.5. The only way to fix this is to edit their plugin to remove the hardcoded version. We don’t like recommending this, but unfortunately, this is the only way to fix the problem.

social warfare query strings
Social Warfare query strings

For Social Warfare, the file you need to edit is the “header-meta-tags.php” file located here: /wp-content/plugins/social-warfare/functions/frontend-output/. You can download it via FTP. By default, here is how the original file looks.

plugin with query strings
Plugin with query strings

You can remove the hard coded SWP_VERSION and it will fix the issue. Below is code to replace lines 86 – 92 in that file, and is what we use on our sites.

// Echo it if we're using the Admin Head Hook
		echo '<style>@font-face {font-family: "sw-icon-font";src:url("' . SWP_PLUGIN_URL . '/fonts/sw-icon-font.eot");src:url("' . SWP_PLUGIN_URL . '/fonts/sw-icon-font.eot?#iefix") format("embedded-opentype"),url("' . SWP_PLUGIN_URL . '/fonts/sw-icon-font.woff") format("woff"),
	url("' . SWP_PLUGIN_URL . '/fonts/sw-icon-font.ttf") format("truetype"),url("' . SWP_PLUGIN_URL . '/fonts/sw-icon-font.svg?#1445203416") format("svg");font-weight: normal;font-style: normal;}</style>';
	else :

		// Add it to our array if we're using the froSntend Head Hook
		$info['html_output'] .= PHP_EOL . '<style>@font-face {font-family: "sw-icon-font";src:url("' . SWP_PLUGIN_URL . '/fonts/sw-icon-font.eot");src:url("' . SWP_PLUGIN_URL . '/fonts/sw-icon-font.eot?#iefix") format("embedded-opentype"),url("' . SWP_PLUGIN_URL . '/fonts/sw-icon-font.woff") format("woff"), url("' . SWP_PLUGIN_URL . '/fonts/sw-icon-font.ttf") format("truetype"),url("' . SWP_PLUGIN_URL . '/fonts/sw-icon-font.svg?#1445203416") format("svg");font-weight: normal;font-style: normal;}</style>';

And as you can see below, the query string on the Social Warfare file is now gone.

Social Warfare after editing
Social Warfare after editing

Was this article helpful?

Related Articles

Leave a Comment