-
-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Could the Vite static asset be cached for longer periods in the client using a service worker, without relying on CDN configuration?
For example, Cloudflare cache rules have to be used to achieve longer cache period. Or else, the asset is cached for 4 hours. (default)
Therefore, if the user revisits the SvelteKit site after 4 hours, it has to make a network request.
This can't be done in Cloudflare Pages alone. A custom domain has to be onboarded to CF, and global cache rules have to be applied.
However, there are some situations where Cache Rules on your custom domain does make sense. For example, you may have easily cacheable locations for immutable assets, such as CSS or JS files with content hashes in their file names. Custom caching can help in this case, speeding up the user experience until the file (and associated filename) changes. Just make sure that your caching does not interfere with any redirects or Functions.
https://developers.cloudflare.com/pages/configuration/serving-pages/#caching-and-performance
Users could opt-into this service worker behavior in the scaffolding process.
Or else, the service worker docs example can be updated, which currently caches all assets on installation.