Skip to content

feat: suppress caching for added project hosts via Cache-Control override#798

Closed
davidnuescheler wants to merge 7 commits intomainfrom
feature/suppress-cache-added-projects
Closed

feat: suppress caching for added project hosts via Cache-Control override#798
davidnuescheler wants to merge 7 commits intomainfrom
feature/suppress-cache-added-projects

Conversation

@davidnuescheler
Copy link
Contributor

Suppresses caching for added project hosts (especially prod) by overriding response headers via the extension's declarativeNetRequest rules.

  • Cache-Control override: For every added project, responses from its prod host, preview host, live host, and review host get Cache-Control: max-age=60 (1 minute), overriding the server's HTML/JSON cache headers.
  • Scope: Applies to GET requests for main_frame, sub_frame, xmlhttprequest, and other (covers HTML and JSON).
  • Config: CACHE_MAX_AGE_SECONDS (default 60) is exported from auth.js for easy tuning.
  • Lifecycle: Header rules are applied at startup and whenever a project is added or updated (and when projects are removed via existing auth reconfig).

…ride

- Add declarativeNetRequest rules that set response header
  Cache-Control: max-age=60 for all added project hosts (prod,
  preview, live, review)
- Overrides server Cache-Control for HTML (main_frame, sub_frame)
  and JSON (xmlhttprequest) to 1 minute
- Re-apply header config when project is added or updated
@codecov
Copy link

codecov bot commented Feb 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Contributor

@rofe rofe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add test cases for getHostDomains() and getCacheControlRules().

Comment on lines 49 to 52
p?.host,
p?.previewHost,
p?.liveHost,
p?.reviewHost,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out we only need rules for host and liveHost. previewHost and reviewHost already have the 60s cache TTL:

Suggested change
p?.host,
p?.previewHost,
p?.liveHost,
p?.reviewHost,
p?.host,
p?.liveHost,

responseHeaders: [{
header: 'Cache-Control',
operation: 'set',
value: `max-age=${CACHE_MAX_AGE_SECONDS}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the must-revalidate

Suggested change
value: `max-age=${CACHE_MAX_AGE_SECONDS}`,
value: `max-age=${CACHE_MAX_AGE_SECONDS}, must-revalidate`,

Comment on lines 73 to 81
'main_frame',
'sub_frame',
'script',
'stylesheet',
'image',
'xmlhttprequest',
'media',
'font',
'other',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually don't need image, media and other

Suggested change
'main_frame',
'sub_frame',
'script',
'stylesheet',
'image',
'xmlhttprequest',
'media',
'font',
'other',
'main_frame',
'sub_frame',
'script',
'stylesheet',
'xmlhttprequest',
'font',

const rules = getCacheControlRules(configs);
expect(rules).to.have.lengthOf(3);
expect(rules.every((r) => r.action?.responseHeaders?.[0]?.header === 'Cache-Control')).to.be.true;
expect(rules.every((r) => r.action.responseHeaders[0].value === `max-age=${CACHE_MAX_AGE_SECONDS}`)).to.be.true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(rules.every((r) => r.action.responseHeaders[0].value === `max-age=${CACHE_MAX_AGE_SECONDS}`)).to.be.true;
expect(rules.every((r) => r.action.responseHeaders[0].value === `max-age=${CACHE_MAX_AGE_SECONDS}, must-revalidate`)).to.be.true;

const { host: adminHost } = new URL(ADMIN_ORIGIN);
const { host: newAdminHost } = new URL(ADMIN_ORIGIN_NEW);

/** Cache-Control max-age in seconds for added project hosts (HTML/JSON). 60 = 1 minute. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Cache-Control max-age in seconds for added project hosts (HTML/JSON). 60 = 1 minute. */
/** Cache-Control max-age in seconds for added project hosts (HTML, JSON and code): 1 minute. */

@rofe
Copy link
Contributor

rofe commented Feb 27, 2026

Doesn't work as expected, Chrome ignores cache instructions for fetch requests.

@rofe rofe closed this Feb 27, 2026
@rofe rofe deleted the feature/suppress-cache-added-projects branch February 27, 2026 15:48
@rofe rofe restored the feature/suppress-cache-added-projects branch February 27, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants