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.

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.