Remove query strings from static resources wordpress

If you are a site proprietor, who is especially careful about your site’s speed, you’re awesome!

Website speed is something that all site proprietors ought to consider imperative – for the most part to move/please customers; to make it pleasant and magnificent for their customers to get to their site.

Furthermore, if you are speed insightful, you should check your site speed on sites like pingdom or GT Metrix.

What’s more, you would have seen a speed recommendation like this: Remove query strings from static resources.

So… what are query strings?

What are these query strings?

Query strings are URLs that have either “?” or “&”.

But why do these appear in the URLs and what’s the cause?

Actually, query strings are used by plugin developers to push updates.

The static assets (like CSS and JS documents) are normally stored as proxy servers or CDNs. What’s more, when a developer needs to push an update, it won’t be rendered quickly because of the caching impacts.

Which is the reason they use query strings to quickly render updates, as query strings won’t be cached.

But as a side effect, since they are not cached, they add to the loading time of a website page.

How to remove query strings from static resources?

Since obviously query strings increase the loading time of your website pages, you should absolutely make sure that you remove those from your static resources.

There are two ways to do it. Either by implementing a code, or using a plugin.

#1 Implementing a code

Indeed, on the off chance that you are sure with adjusting the code and in the event that you recognize what you are doing, this is the most ideal approach to do it.

In any case, in the event that you are not exceptionally sure about adjusting site codes, it is smarter to pick alternative #2.

You have to add the following code in the function.php file of your site. You can do this in three ways:

  • Either through your WordPress Dashboard
  • Through online File Manager
  • Through FTP

However you do this, make sure you take a backup of your functions.php file so you don’t break anything.

Paste the following code in the functions.php file and save:

// Remove query string from static files 
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 );

#2 Use a plugin to remove query strings

Installing a plugin for this is the simplest way to deal with this, if you are not very skillful in editing the code.

Install any one of them to get the job done!

Remove query strings,Speed Booster Pack

Remove query strings from static resources using any one of these techniques and enjoy a boost in loading speed of your website!

Please check the below video where I have shown the first method of doing it. please like share and comment and do subscribe to my channel

Leave a Comment