How to Remove Query Strings from Static Resources [WordPress]

query string FI

This tutorial well help you to Remove Query Strings from Static Resources like JavaScript (.js) and CSS (.css) files on WordPress platform. Why we need to remove that?, if you really care about the speed of your site you have to do this as and Google Page Speed may suggest you to remove query string.
Check your blog using GTMetrix now. Just put URL your website in the Text box and gtmetrix will analyze your website. When it has completed, you will see your Page Grade and some suggestions to improve your website speed by doing some tweaks.

Remove Query Strings from Static Resources

One of the recommendations is Remove Query Strings from Static Resources.

According to GTMetrix
Most proxies, most notably Squid up through version 3.0, do not cache resources with a “?” in their URL even if a Cache-control: public header is present in the response. To enable proxy caching for these resources, remove query strings from references to static resources, and instead encode the parameters into the file names themselves.

Right click in your website and choose View Page Source. Press Ctrl+F and type .css or .js. You should see something like this

This is the simple and proven solution to Remove Query Strings from Static Resources

You will need to locate your functions.php file. Usually just go to Appearance –> Editor — > functions.php in your WordPress admin page.

Be careful when editing functions.php. I suggest to back it up first in case you make a mistake.

Add this following code in bottom of your functions.php just before the ?>

Go back and do View Page Source again. This time no more query string on your CSS and Javascript URLā€™s.

Check again your website in GTMetrix and you will see the difference.
So in less than 10 minutes we have just improved the speed of a website.
I hope this tutorial is useful and don’t forget to share it šŸ™‚

Facebook Comments

Agung Setiawan

Agung Setiawan adalah software engineer di, penulis sekaligus pecinta sastra, dan pembaca buku

Halo, perkenalkan saya Agung Setiawan.
Seorang Software Engineer di BukaLapak, penulis buku, blogger, gunpla builder, tech educator.
Simak pemikiran saya soal dunia Software Engineering via Twitter di @agungsetiawanmu dan facebook
Mau belajar Vim bareng saya?
Belajar ngoding dari nol menggunakan PHP

Leave a Reply

Your email address will not be published. Required fields are marked *