Every stray query string tacked onto a static file fractures your CDN cache and hammers your origin. If three visitors hit style.css?v=1.2, style.css?v=1.2&utm_source=twitter, and plain old style.css, an unconfigured CDN caches three identical copies of the exact same bytes. Here is how I set up StackPath CDN to strip query strings on static assets like CSS, JavaScript, and fonts so every request lands squarely on edge cache.
I learned this the hard way during a chaotic WooCommerce product launch. Paid campaigns flooded the store with tracking parameters, and our plugins blindly inherited those query strings across script enqueues. Origin CPU shot past 90%, and our edge cache hit ratio hovered at an embarrassing 41%. Forcing StackPath to drop query strings from asset cache keys dragged that hit ratio up to 98.4% and dropped asset latency from 310ms down to 19ms.

Why Query Strings Murder Your CDN Cache Hit Ratio
By default, HTTP caching proxies build cache keys from the entire request URI. Per RFC 7234 caching rules, query strings are baked into that key. Change a single character in the parameter list, and the edge treats it as an outright miss, forwarding the request straight to PHP and your web server.
WordPress is the worst offender here. Anytime you register a script or style with wp_enqueue_script, it quietly tacks on ?ver=X.X.X. Ad trackers, analytics bots, and social referrers pile on with ?fbclid=, ?gclid=, and random timestamps.
Here is what happens when 1,000 users land on your site with unique tracking parameters:
- Default cache key: 1,000 distinct query strings spawn up to 1,000 origin hits. Your PHP workers churn through memory just to serve the exact same CSS file 1,000 times.
- Ignored query strings: All 1,000 requests map to one cache key (e.g.,
/wp-content/themes/custom/app.js). The first visitor primes the edge; the next 999 get served straight from StackPath POP storage in under 25ms.
If you run carts or dynamic sessions on the same domain, pair this configuration with my guide on how to bypass CDN cache for logged-in WordPress users in StackPath.
Method 1: Global Query String Caching in the StackPath Portal
StackPath has a blunt, site-wide switch for query strings. It works fine if your CDN site is a dedicated media host (like cdn.example.com) that only delivers static files and never handles dynamic backend routes.
- Log in to the StackPath Control Portal.
- Click Sites on the left and select your CDN site.
- Open the Caching tab.
- Find the Cache Query String setting.
- Switch the dropdown from Cache Query String to Ignore Query String.
- Hit Save.
With this enabled, StackPath strips the entire query string when looking up assets in local edge storage. A hit for /logo.png?width=200 or /logo.png?v=99 retrieves the cached object for /logo.png.
The problem? It hits everything on that site. If you route API endpoints through the same hostname (say, /api/products?page=2), StackPath will serve page 1 to everyone who asks for page 2. If your CDN covers mixed traffic, skip this global toggle and use EdgeRules instead.
Method 2: Target Static Extensions with StackPath EdgeRules
EdgeRules give you pinpoint control. We can tell StackPath to strip query parameters only when the request matches static file extensions, leaving your APIs, query-based search filters, and checkout endpoints completely untouched.
- In your StackPath Site dashboard, head to the EdgeRules tab.
- Click Add EdgeRule.
- Label it:
Static Assets - Ignore Query Strings. - Under If (Conditions), pick URL and set the operator to matches regex.
- Paste this regex pattern into the value field:
.(?:css|js|jpe?g|png|gif|ico|webp|avif|svg|woff2?|ttf|eot|otf)(?.*)?$Now configure what StackPath should do with those files:
- Under Then (Actions), click Add Action.
- Select Override Cache Policy (or Cache Query String depending on your portal version).
- Choose Ignore Query String.
- Add a second action: Edge Cache TTL and set it to 7 days (604800 seconds) or whatever cache window fits your deployment cycle.
- Click Save EdgeRule.
StackPath syncs EdgeRules across its POPs in about 30 to 60 seconds. Once propagated, any request hitting those file extensions drops its query parameters before evaluating the cache key.
While tweaking edge headers for static assets, make sure you don’t break icon fonts. Check out my guide on how to fix CORS errors on web fonts and static assets in StackPath.
Testing Cache Hits and Misses Using cURL
Do not test CDN rules in your browser. Local browser disk caching hides what the edge edge POP is actually doing. Fire up your terminal and run curl -I to inspect raw response headers directly.
Send a request to a CSS file on your domain with a random query string:
curl -I "https://cdn.example.com/wp-content/themes/mytheme/style.css?testcache=run1"The first attempt will show a cache miss if that specific POP has not cached the asset yet:
HTTP/2 200
server: StackPath
date: Sun, 15 Oct 2023 14:10:02 GMT
content-type: text/css; charset=UTF-8
cache-control: public, max-age=604800
x-cache: MISS
x-hw: 1697379002.dop014.pa2.t, 1697379002.cds021.pa2.cImmediately run the request again, but change the query string value completely:
curl -I "https://cdn.example.com/wp-content/themes/mytheme/style.css?testcache=run2"If your EdgeRule works, you will get an immediate cache hit despite the different query parameter:
HTTP/2 200
server: StackPath
date: Sun, 15 Oct 2023 14:10:05 GMT
content-type: text/css; charset=UTF-8
cache-control: public, max-age=604800
age: 3
x-cache: HIT
x-hw: 1697379005.dop014.pa2.t, 1697379005.cds021.pa2.h Check the x-cache: HIT and age: 3 headers. StackPath stripped testcache=run2 and served the cached asset primed by run1. The asset returned in 18ms instead of forcing a 240ms round-trip back to origin.
The Real Gotcha: Cache Busting When You Ship Code
Ignoring query strings fixes cache fragmentation, but it introduces a major deployment trap: old-school query-string cache busting (like style.css?v=2.0) no longer does anything.
If you push changes to bundle.js and change your HTML tag to bundle.js?v=1.0.2, StackPath ignores that version string. Visitors keep getting the old v=1.0.1 file from edge storage until the TTL runs out or you manually purge it.
Here are the two ways to handle this cleanly:
Option A: Adopt File Fingerprinting (Recommended)
Use file fingerprinting (content hashing). Modern bundlers like Vite, Webpack, and esbuild generate hashed filenames like bundle.a9f4c1.js. When your source code changes, the file path itself changes. The edge sees a brand-new URL and fetches the update without caring about query parameters.
Option B: Automated API Purge on Deploy
If you run WordPress or an older stack where renaming output files is painful, make your deployment pipeline purge StackPath automatically. You can hook into the StackPath API with a simple curl call in your CI/CD runner.
Here is the bash script I use to authenticate and purge updated assets:
#!/usr/bin/env bash
set -euo pipefail CLIENT_ID="your_stackpath_client_id"
CLIENT_SECRET="your_stackpath_client_secret"
STACK_ID="your_stack_id"
SITE_ID="your_site_id" # 1. Obtain Bearer Token
AUTH_RESPONSE=$(curl -s -X POST "https://gateway.stackpath.com/identity/v1/oauth/token" -H "Content-Type: application/json" -d "{ "client_id": "${CLIENT_ID}", "client_secret": "${CLIENT_SECRET}", "grant_type": "client_credentials" }") ACCESS_TOKEN=$(echo "${AUTH_RESPONSE}" | grep -o '"access_token":"[^"]*' | cut -d'"' -f4) # 2. Trigger Purge for Modified Assets
curl -s -X POST "https://gateway.stackpath.com/cdn/v1/stacks/${STACK_ID}/sites/${SITE_ID}/purge" -H "Authorization: Bearer ${ACCESS_TOKEN}" -H "Content-Type: application/json" -d '{ "items": [ {"url": "https://example.com/wp-content/themes/mytheme/style.css", "recursive": false}, {"url": "https://example.com/wp-content/themes/mytheme/app.js", "recursive": false} ] }' echo "StackPath asset purge submitted successfully."Trigger this right after your deployment sync finishes so users never load mismatched, half-updated code.
Stripping Version Query Strings at the WordPress Origin
StackPath fixes the edge cache, but leaving messy version strings in your raw HTML still clutters markup and triggers warnings on tools like GTmetrix. You can strip them out at the origin before WordPress prints script and link tags.
Drop this into your child theme’s functions.php or a custom site plugin:
<?php
declare(strict_types=1); /** * Remove query strings from static assets for non-admin requests. */
function isitdev_clean_asset_query_strings(string $src): string
{ if (is_admin()) { return $src; } if (strpos($src, '?ver=') !== false) { $src = remove_query_arg('ver', $src); } return $src;
} add_filter('style_loader_src', 'isitdev_clean_asset_query_strings', 10, 1);
add_filter('script_loader_src', 'isitdev_clean_asset_query_strings', 10, 1); This hook intercepts every registered style and script tag. If it finds a ?ver= parameter, it rips it out. Notice the !is_admin() check—we leave query strings alone inside wp-admin so core and plugin dashboard updates don’t break on stale browser caches.
Pairing this with origin-level caching keeps server load rock-bottom. See my write-up on how to reduce WordPress TTFB on Hostinger with LiteSpeed Cache for a solid origin setup.
Configuring Origin Cache-Control Headers for Static Files
StackPath respects your origin server’s headers unless an EdgeRule forces an override. To make sure static files stay warm in both edge and browser caches, your origin needs clear Cache-Control headers.
If you run Apache or LiteSpeed, put this in your .htaccess:
Header set Cache-Control "public, max-age=2592000, stale-while-revalidate=86400"
If you run Nginx, add this to your server {} block:
location ~* .(css|js|woff2|jpg|jpeg|png|webp|svg|ico)$ { expires 30d; add_header Cache-Control "public, max-age=2592000, stale-while-revalidate=86400"; access_log off;
}The stale-while-revalidate directive is a lifesaver. It allows StackPath to serve an expired asset from cache in 15ms while quietly revalidating with your origin in the background. If you want to protect your server during sudden traffic surges, review our setup for preventing CDN cache stampedes with origin shield and stale-while-revalidate.
Frequently Asked Questions
Will ignoring query strings break Google Analytics or UTM tracking?
No. UTM parameters and campaign tracking tokens are appended to the HTML document URL (like https://example.com/?utm_source=newsletter). Your static asset EdgeRule only fires on asset extensions (.css, .js, images), leaving document requests and tracking tags completely untouched.
Can I ignore query strings on images but keep them for dynamic resizing scripts?
Yes. If you route images through a dynamic resizing script (like image.php?w=300&h=200), adjust your EdgeRule regex so it doesn’t match .php, or scope the rule specifically to static directories like /wp-content/uploads/ and /assets/.
How long does an EdgeRule change take to propagate across StackPath?
StackPath pushes EdgeRules to its global edge POPs within about 60 seconds. Keep in mind that files cached before you created the rule will remain stored under their old cache keys until their TTL runs out or you run a purge.
Does ignoring query strings interfere with WooCommerce or shopping carts?
No, provided your rule is restricted to static extensions. WooCommerce manages cart sessions via cookies and dynamic endpoints (like /?wc-ajax=get_refreshed_fragments). Because those hit PHP endpoints instead of .css or .js files, your checkout and cart operations run completely normally.
Next Steps
Once your static assets are caching consistently regardless of query strings, take a look at how your origin handles cache expiries. If you see sudden database spikes when clearing cache under heavy traffic, read our guide on preventing CDN cache stampedes with Origin Shield next.

