Issue
The Time to First Byte (TTFB) for individual product pages in the WooCommerce store is as high as 2.5 seconds, even though WP Rocket page caching is enabled and the homepage caches correctly (0.18 s).
Using curl to trace the request step-by-step reveals that the product page undergoes three server-side redirects before reaching the final cached page:
/item/flarum/ →301→ /item/flarum (0.78 s — WordPress removes trailing slash)
/item/flarum →307→ /item/flarum/?v=160222... (0.81 s — WC geolocation appends ?v= and re-adds trailing slash)
/item/flarum/?v= →301→ /item/flarum?v=160222... (0.75 s — WordPress again removes trailing slash)
/item/flarum?v= →200 (0.18 s — cache hit)
Although the final page is successfully cached by WP Rocket (0.18 s), users must endure three sequential server redirects (~2.3 s total) just to reach it.
Root Cause Analysis
The root cause lies in WooCommerce core’s WC_Cache_Helper::geolocation_ajax_redirect() method (in class-wc-cache-helper.php).
When woocommerce_default_customer_address is set to geolocation_ajax, WooCommerce issues a 307 redirect on every non-cart/non-checkout page, appending a ?v= parameter containing a geolocation hash to the URL — enabling region-specific cache variants.
The problem arises during redirect URL construction:
$redirect_url = trailingslashit( home_url( $wp->request ) );
trailingslashit() forcibly adds a trailing slash. However, if WordPress’s permalink structure excludes trailing slashes (e.g., /%category%/%postname%), WordPress itself will issue another 301 redirect to strip it off. This creates a cascade:
- WordPress 301 — removes trailing slash
- WooCommerce 307 — appends
?v=and reintroduces the trailing slash - WordPress 301 — removes trailing slash again
- Final cache hit
Each redirect incurs a full round-trip server request (~0.7–0.8 s), resulting in ~2.3 s of pure overhead.
Solution
For digital-goods stores (e.g., plugins, themes, software) that do not require region-based pricing or tax rules, simply disable geolocation_ajax:
wp option update woocommerce_default_customer_address base_address --url=mall.weixiaoduo.com
This changes the default customer address setting from geolocation_ajax to base_address (i.e., use the store’s base address for all users).
After applying the change, clear your page cache so WP Rocket regenerates cached files without the ?v= parameter.
Impact After Fix
| Metric | Before Fix | After Fix |
|---|---|---|
| Product Page TTFB (first visit) | ~2.5 s (3 redirects) | ~1.2 s (direct render) |
| Product Page TTFB (cached) | ~2.5 s (redirects are uncacheable) | 0.17 s (direct cache hit) |
| 307 Redirects | Triggered on every visit | Fully eliminated |
| Homepage TTFB | 0.18 s (unaffected) | 0.17 s (unchanged) |
Applicable Scenarios
- Digital-goods stores (plugins, themes, software, etc.) where pricing/taxation does not vary by location
- Stores using WP Rocket or similar page-caching plugins
- Sites with permalink structures excluding trailing slashes (e.g.,
/%postname%/)
If your store does require geo-specific pricing or tax rates and cannot disable geolocation entirely, consider an alternative: create a must-use plugin (mu-plugin) that hooks into geolocation_ajax_redirect before the redirect occurs and strips trailingslashit() from the URL construction — reducing the redirect chain by at least one hop.
Debugging Steps
Trace the redirect chain using curl:
# Check for 307 redirects
curl -sS -D - -o /dev/null "https://your-domain.com/product/slug" 2>&1 | grep -iE "HTTP/|location|cache"
# Follow full redirect chain & measure TTFB per hop
curl -sS -o /dev/null -w "TTFB: %{time_starttransfer}s | HTTP: %{http_code}\n" -L "https://your-domain.com/product/slug"
# Verify current setting
wp option get woocommerce_default_customer_address
If you observe a 307 redirect with a Location header containing ?v=, geolocation_ajax is active and causing the issue.