Skip to content

perf: replace ISR with CDN cache for versioned code and docs routes#2297

Merged
danielroe merged 1 commit intonpmx-dev:mainfrom
JohnPhamous:perf/cdn-cache-versioned-routes
Mar 27, 2026
Merged

perf: replace ISR with CDN cache for versioned code and docs routes#2297
danielroe merged 1 commit intonpmx-dev:mainfrom
JohnPhamous:perf/cdn-cache-versioned-routes

Conversation

@JohnPhamous
Copy link
Copy Markdown
Contributor

@JohnPhamous JohnPhamous commented Mar 27, 2026

  • Replace isr: true with s-maxage CDN cache headers on /package-code/** and /package-docs/**
  • These routes serve immutable, versioned content (e.g. /package-code/vue/v/3.4.0/src/index.ts)
  • ISR cache data shows 145:1 write-to-read byte ratio — >99% of durable storage entries are never read
  • /package-code/ alone accounts for ~81% of all ISR write units (6.4M/7.9M per 12h)
  • Vercel CDN caches (s-maxage) are free and equivalent for immutable content
  • API handler caching (defineCachedEventHandler) is unaffected

Expected impact: ~80% reduction in ISR write volume

What's lost

Feature lost Why acceptable
ISR durable storage fallback 145:1 write:read ratio — barely used. CDN eviction → function re-renders (714ms P75).
Request collapsing Millions of unique URLs → concurrent requests to same file are extremely rare.
Cache persistence across deploys <1% of writes are ever read — deploy cold-cache has negligible impact.

These routes serve immutable, versioned package content (e.g.
/package-code/vue/v/3.4.0/src/index.ts). With ISR enabled, every
unique URL writes to durable storage — but ISR cache data shows a
145:1 write-to-read byte ratio, meaning >99% of entries are never
read again. This route alone accounts for ~81% of all ISR write units.

Switch to CDN cache via s-maxage headers. Vercel CDN caches are free
and provide equivalent behavior for immutable content. API handler
caching (defineCachedEventHandler) is unaffected.

Expected impact: ~80% reduction in ISR write volume.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Mar 27, 2026 5:48pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Mar 27, 2026 5:48pm
npmx-lunaria Ignored Ignored Mar 27, 2026 5:48pm

Request Review

@github-actions
Copy link
Copy Markdown

Hello! Thank you for opening your first PR to npmx, @JohnPhamous! 🚀

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any issues you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Vercel

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

The pull request modifies the nuxt.config.ts file to update cache configuration for two wildcard page routes. Specifically, the routes '/package-code/**' and '/package-docs/**' have been changed from using incremental static regeneration (ISR) with a cache configuration to using explicit HTTP Cache-Control headers instead. The new headers specify public caching with a one-year maximum age and stale-while-revalidate directive. This represents 6 additions and 2 deletions, with no changes to exported entities or other route rules.

🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description clearly explains the changes made, their rationale, and expected impact with detailed metrics.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
nuxt.config.ts (1)

170-175: Optional tidy-up: extract the repeated Cache-Control value into a constant.

This avoids policy drift if you tweak TTL/SWR later.

♻️ Proposed refactor
 const isStorybook = process.env.STORYBOOK === 'true' || process.env.VITEST_STORYBOOK === 'true'
+const VERSIONED_ROUTE_CACHE_CONTROL = 'public, s-maxage=31536000, stale-while-revalidate=31536000'
@@
     '/package-code/**': {
-      headers: { 'Cache-Control': 'public, s-maxage=31536000, stale-while-revalidate=31536000' },
+      headers: { 'Cache-Control': VERSIONED_ROUTE_CACHE_CONTROL },
     },
     '/package-docs/**': {
-      headers: { 'Cache-Control': 'public, s-maxage=31536000, stale-while-revalidate=31536000' },
+      headers: { 'Cache-Control': VERSIONED_ROUTE_CACHE_CONTROL },
     },

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5352c9b4-af4e-4b59-879e-db5cfa63be3b

📥 Commits

Reviewing files that changed from the base of the PR and between 873562d and 2c1fe51.

📒 Files selected for processing (1)
  • nuxt.config.ts

Copy link
Copy Markdown
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

❤️

@danielroe danielroe added this pull request to the merge queue Mar 27, 2026
Merged via the queue into npmx-dev:main with commit 89e2431 Mar 27, 2026
23 checks passed
@github-actions github-actions bot mentioned this pull request Mar 27, 2026
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