WordPress Speed Optimization: Removing Query Strings from Assets

Query strings appended to CSS and JavaScript file URLs (like style.css?ver=6.4) are how WordPress busts browser and CDN caches when a theme or plugin updates a file — but some caching/CDN layers and page-speed testing tools flag them as a performance issue, since certain proxies won’t cache a URL that includes a query string. Option […]

Wordpress Speed Up Remove Query Strings From Static Resources
Query strings appended to CSS and JavaScript file URLs (like style.css?ver=6.4) are how WordPress busts browser and CDN caches when a theme or plugin updates a file — but some caching/CDN layers and page-speed testing tools flag them as a performance issue, since certain proxies won’t cache a URL that includes a query string.

Option 1 — A Caching Plugin Setting

If you’re already running a caching plugin (LiteSpeed Cache, WP Rocket, and others), check its optimization settings first — most include a one-click “Remove query strings from static resources” toggle that handles this without touching any code.

Option 2 — A Small Code Snippet

If you’d rather not rely on a plugin setting, this snippet in your child theme’s functions.php strips the ver parameter from enqueued styles and scripts:
function tgh_remove_query_strings($src) {
    if (strpos($src, 'ver=')) {
        $src = remove_query_arg('ver', $src);
    }
    return $src;
}
add_filter('style_loader_src', 'tgh_remove_query_strings', 10, 1);
add_filter('script_loader_src', 'tgh_remove_query_strings', 10, 1);
Note that removing the version query string also removes its cache-busting function — if you (or a plugin) update a CSS/JS file, visitors’ browsers may keep serving a stale cached copy until their local cache naturally expires, so weigh the modest speed-test score improvement against that trade-off.

Is This Still Worth Doing? (Updated for 2026)

Worth flagging up front: this is now a deprecated recommendation. GTmetrix’s own guidance page for it is titled outright “Remove query strings from static resources (deprecated)” — the original rationale (older proxies like Squid 3.0 refusing to cache a URL containing a ?) stopped applying once modern CDNs and browsers began caching based on Cache-Control response headers rather than URL syntax. Current Google Lighthouse/PageSpeed Insights audits don’t check for query strings at all — the nearest modern equivalent is “Serve static assets with an efficient cache policy,” which has nothing to do with a ?ver= string. WP Rocket removed its own version of this toggle back in version 3.6, with the development team stating outright that GTmetrix no longer factors query strings into its performance grades. If you’re setting up caching on a current build, skip this one and look at filename-based cache busting instead — baking a content hash into the filename itself (e.g. style.a1b2c3.css) paired with a long, immutable Cache-Control header gets you both aggressive caching and reliable invalidation, without the URL-syntax workaround this post describes.

Resources

Remove Query Strings From Static Resources

Discover more from TechyGeeksHome

Subscribe to get the latest posts sent to your email.

Andrew Armstrong

Andrew Armstrong is a UK-based IT professional with 26+ years of hands-on experience in Windows, Windows Server, SCCM/ConfigMgr, Active Directory, PowerShell, and enterprise infrastructure.

He founded TechyGeeksHome in 2010 and has published over 1,500 practical guides covering real-world IT problems and solutions. When not solving IT problems,

Andrew develops free Windows utilities including Ultimate Settings Panel, which has been downloaded over 850,000 times.

5 thoughts on “WordPress Speed Optimization: Removing Query Strings from Assets

  1. A great plugin that work perfectly. I reduced the load time to 2sec from 5sec

Comments are closed.