Prevent page caches from storing content-negotiation redirect#31
Open
TBarregren wants to merge 1 commit intoProgressPlanner:mainfrom
Open
Prevent page caches from storing content-negotiation redirect#31TBarregren wants to merge 1 commit intoProgressPlanner:mainfrom
TBarregren wants to merge 1 commit intoProgressPlanner:mainfrom
Conversation
Member
|
Hmm this solution would prevent caching everywhere, including in solutions that do understand they should... vary cache, by |
25e5ecd to
3d68a48
Compare
Many full-page caches do not vary their cache key by the Accept request header. When they store the 303 redirect from content negotiation, all subsequent visitors are redirected to the .md URL instead of seeing the HTML page. Two complementary layers prevent this: - Cache-Control: private header prevents shared caches (CDNs, reverse proxies) from storing the redirect while allowing browser caching. - DONOTCACHEPAGE constant and LiteSpeed API call tell WP-level page caches not to store the response. This is behind a filter (markdown_alternate_disable_page_cache_on_redirect) so sites with Vary-aware caching can opt out. The .md URLs themselves remain fully cacheable. Fixes ProgressPlanner#30 Co-Authored-By: Claude <noreply@anthropic.com>
3d68a48 to
ec59c33
Compare
Author
|
Thanks for the feedback @jdevalk — fair point. I've reworked the fix: What changed:
add_filter( 'markdown_alternate_disable_page_cache_on_redirect', '__return_false' );The idea is that |
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.
Summary
Vary: Acceptheader and store the 303 redirect fromhandle_accept_negotiation()keyed by URL alone.mdURL instead of seeing the HTML pageThe Fix
Three complementary layers added before the redirect in
handle_accept_negotiation():DONOTCACHEPAGEconstantCache-Control: private, no-storedo_action('litespeed_control_set_nocache')The
.mdURLs themselves remain fully cacheable — only the content-negotiation redirect (which depends on theAcceptheader) is excluded from caching.Test Plan
Accept: text/markdownreturns 303 withCache-Control: private, no-store:curl -sI -H "Accept: text/markdown" https://example.com/some-page/.mdURL returns 200 withtext/markdowncontent type:Fixes #30
Relates to PITFALLS.md Pitfall #5 ("Content Negotiation Interferes with Caching")
🤖 Generated with Claude Code