How to delete the query string illustration of the static resource URL address of a WordPress website

When it comes to WordPress performance, the query string problem for static resource URL addresses is essential. The CSS and JavaScript files of a Web site usually have file versions, such asdomain.com/style.css?ver=4.6, at the end of their URL. Some servers and proxy servers cannot cache query strings, andcache-control:publicheaders exist immediately.

removes them and sometimes improves the cache. This will also fix the warning you may see in Web site performance testing tools such as GTMetrix and Pingdom, that is, “remove query strings from static resources.”

How to delete the query string illustration of the static resource URL address of a WordPress website1

removes the query string

from static resources remember that query strings are usually set for a reason. WordPress developers use file versioning to resolve caching issues. For example, if they update a version ofstyle.css, iterating from?ver=4.6to?ver=4.7, it will be considered a brand new URL and will not be cached. If you delete the query string and update the plug-in, it may cause the browser to continue using the cached version. In some cases, this may affect the appearance of the page until the cache resource expires or the cache is completely refreshed. The

query string is also used in the development workflow to facilitate the development of tracking versions.

delete static resources URL address query strings

you can delete query strings in two different ways, one is to use a small amount of code, and the other is to use the WordPress plug-in.

  1. uses code to delete query strings from static resources
  2. uses plug-ins to delete query strings


1. 0 from static resources. Using code to remove the query string

from a static resource, you can delete the query string for the static resource URL address in a few lines of code. Simply add the following to thefunctions.phpfile of the WordPress theme.

function remove_query_strings() {
   if(!is_admin()) {
       add_filter('script_loader_src', 'remove_query_strings_split', 15);
       add_filter('style_loader_src', 'remove_query_strings_split', 15);
   }
}

function remove_query_strings_split($src){
   $output = preg_split("/(&ver , ?ver)/", $src);
   return $output[0];
}
add_action('init', 'remove_query_strings');

important tip: if the operation is not correct, editing the source code of the WordPress theme may affect the operation of the website. If you are not familiar with the code, it is recommended to find a developer to do it. Or, you can use the free Code Snippets plug-in to support adding the above code as a plug-in, and you don’t have to worry that adding code will paralyze the site.

just needs to create a new code snippet and add the above code. Select run only in front of the site, and then save the code snippet. The query string will be deleted! You may need to clear the WordPress site cache to see the changes take effect at the front end.

How to delete the query string illustration of the static resource URL address of a WordPress website2

delete query string code segment

with query string (before code)
This is an example of loading a script using a query string.

How to delete the query string illustration of the static resource URL address of a WordPress website3

request with query string

has no query string (after code)
This is an example of a script after deleting a query string.

How to delete the query string illustration of the static resource URL address of a WordPress website4

does not have a query string for the request


2. Use the plug-in to delete the static resource URL address query string

if you don’t want to manipulate the code, another alternative is to use the WordPress plug-in. By installing and enabling the Perfmatters plug-in, you can delete the query string for the static resource URL address with the click of a button. Of course, in addition to this feature, plug-ins can also help you achieve other optimizations for WordPress sites.

How to delete the query string illustration of the static resource URL address of a WordPress website5

uses the Perfmatters plug-in to delete query strings

No more query strings

passes any of the above options, and then use website speed testing tools such as GTMetrix or Pingdom to test the site, and the warning about the query string completely disappears.

How to delete the query string illustration of the static resource URL address of a WordPress website6

fixed “Delete static Resource Police query string” warning

Disclaimer: All articles on this website, unless otherwise specified or marked, are original and published on this website. Any individual or organization is prohibited from copying, stealing, collecting, or publishing the content of this site to any website, book, or other media platform without the consent of this site. If the content on this website infringes on the legitimate rights and interests of the original author, you can contact us for assistance.