Skip to content

Add example of sane cache-control settings when hosting a vite SPA#512

Merged
mcollina merged 1 commit intofastify:mainfrom
codyzu:cache-example
Mar 2, 2025
Merged

Add example of sane cache-control settings when hosting a vite SPA#512
mcollina merged 1 commit intofastify:mainfrom
codyzu:cache-example

Conversation

@codyzu
Copy link
Copy Markdown
Contributor

@codyzu codyzu commented Feb 28, 2025

Adds a sane example of how one might setup the cache-control headers when using fastify-static to host a site, in particular a site built with vite.js

I've been burnt by this recently and I thought it could help others if it was front and center in the docs. In particular, looking at the existing examples, one might think that setting cacheControl: false will disable caching when in fact it will simply disable setting the header and let the browser to it's default caching (which is rarely the desired outcome).

related to #508 & #477

Not sure if this merits an example front in center in the readme, but it would have saved me some headache in some personal projects.

Checklist

Copy link
Copy Markdown
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@mcollina mcollina merged commit ac6fadc into fastify:main Mar 2, 2025
@codyzu codyzu mentioned this pull request Mar 9, 2025
4 tasks
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