Skip to content

feat(vite): add cache-control route rule header to immutable client assets - #3586

Merged
pi0 merged 13 commits into
nitrojs:v3from
hi-ogawa:09-24-feat_vite_add_cache-control_to_immutable_client_assets
Sep 25, 2025
Merged

pi0 merged 13 commits into
nitrojs:v3from
hi-ogawa:09-24-feat_vite_add_cache-control_to_immutable_client_assets

Conversation

@hi-ogawa

Copy link
Copy Markdown
Contributor

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This PR updated vite plugin to automatically configure maxAge for static assets under build.assetsDir https://vite.dev/config/build-options.html#build-assetsdir.

To verify, I add client environment build to playground. But I'm actually failed to verify, so there might be something wrong.

cd playground
pnpm build
node .output/server/index.mjs
curl -v http://[::]:3000/assets/client-BXVNzxyk.js  # no cache-control header

Oddly, with Vercel preset NITRO_PRESET=vercel pnpm build, I can see cache-control is added in .vercel/output/config.json.

{
  "version": 3,
  "overrides": {},
  "routes": [
    {
      "src": "/assets/(.*)",
      "headers": {
        "cache-control": "public,max-age=31536000,immutable"
      },
      "continue": true
    },
...

I'm digging in further, but let me open this as a draft to share the current state as I might be missing something obvious. I would appreciate any help!

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel

vercel Bot commented Sep 24, 2025

Copy link
Copy Markdown

@hi-ogawa is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread src/build/vite/plugin.ts Resolved
@pi0

pi0 commented Sep 24, 2025

Copy link
Copy Markdown
Member

@hi-ogawa pushed few refactors to sync route rules. It should be fixed now can you please confirm if it was your intended behavior:

image

@pi0
pi0 marked this pull request as ready for review September 24, 2025 11:47

@hi-ogawa hi-ogawa left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Looks great!

Comment thread src/build/vite/plugin.ts Resolved
Comment thread src/build/vite/plugin.ts Resolved
@pi0 pi0 changed the title feat(vite): add cache-control to immutable client assets feat(vite): add cache-control route rule header to immutable client assets Sep 25, 2025
@pi0
pi0 merged commit 440c34d into nitrojs:v3 Sep 25, 2025
@hi-ogawa
hi-ogawa deleted the 09-24-feat_vite_add_cache-control_to_immutable_client_assets branch September 26, 2025 00:53
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.

[vite] add cache-control to client assets in assetsDir

2 participants