fix: skip temporary Cache-Control header on non-cacheable pages - #1135
Open
selul wants to merge 1 commit into
Open
fix: skip temporary Cache-Control header on non-cacheable pages#1135selul wants to merge 1 commit into
selul wants to merge 1 commit into
Conversation
While page profiling is pending, replace_content() sent 'Cache-Control: max-age=300' for every not-logged-in request with headers still unsent. Because PHP's header() replaces same-name headers, it overwrote the no-cache header WooCommerce sets on cart, checkout and account pages, letting proxies cache user-specific pages for five minutes. The header is now sent only when DONOTCACHEPAGE is not set and no Cache-Control header exists yet, so a no-cache or longer-lived policy set by WordPress, WooCommerce or a cache plugin is never overridden. The new optml_send_temporary_cache_header filter lets developers override the decision in both directions. Fixes #1082 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While page profiling was pending, Optimole sent
Cache-Control: max-age=300on every not-logged-in request, and PHP'sheader()replaced the no-cache header WooCommerce sets on cart and checkout — so proxies could cache user-specific pages for five minutes (issue #1082). The header is now sent only when the page carries no signal against caching.What changed
should_send_temporary_cache_header()— new decision guard inOptml_Manager. The header is skipped whenDONOTCACHEPAGEis set, or when anyCache-Controlheader exists already.Never override, never downgrade — before: the header replaced whatever
Cache-Controlwas set, including WooCommerce'sno-cache, must-revalidate, max-age=0and longer-lived policies from cache plugins. After: an existingCache-Controlheader always wins.optml_send_temporary_cache_headerfilter — receives the computed decision; developers can force the header off or on contextually.Cacheable pages keep the current behavior — a page with no blocking signal still gets
max-age=300while its profile is pending.Note
Explicit
is_cart()/is_checkout()/is_account_page()exclusions are not needed: WooCommerce sets bothDONOTCACHEPAGEand its no-cache header attemplate_redirect, long before the buffer flush where Optimole runs, so both signals are honored. The same applies to EDD and membership plugins that usenocache_headers().Header decision
flowchart LR A[Profiling pending<br/>for this page] --> B{New:<br/>DONOTCACHEPAGE<br/>set?}:::added B -- Yes --> S[Skip header] B -- No --> C{New:<br/>Cache-Control<br/>already set?}:::added C -- Yes --> S C -- No --> F[New:<br/>optml_send_temporary_cache_header]:::added F --> D[Send max-age=300] classDef added fill:#1a7f37,color:#fff,stroke:#116329,stroke-width:3pxQA
On a connected site with WooCommerce active, clear stored profiles:
Then request the checkout page as a guest:
curl -sI https://your-site.test/checkout/ | grep -i cache-controlExpect:
Cache-Control: no-cache, must-revalidate, max-age=0(WooCommerce's header). Without this fix, the output isCache-Control: max-age=300.Request a plain blog post as a guest directly after clearing transients:
curl -sI https://your-site.test/hello-world/ | grep -i cache-controlExpect:
Cache-Control: max-age=300— the pending-profile behavior on cacheable pages is unchanged.Add
add_filter( 'optml_send_temporary_cache_header', '__return_false' );to the theme'sfunctions.php. Repeat step 2.Expect: no
Cache-Control: max-age=300on any page.🤖 Generated with Claude Code