-
-
Notifications
You must be signed in to change notification settings - Fork 428
Feature request: custom cache-control headers #567
Comments
This has become mission critical for me I think. The problem is that whenever I deploy, cloudflare/browsers cache the old pages with old asset references for 10 minutes, which appears to mean that the site runs, but in some weird half-broken state for all my users, who become immensely irritated since buttons stop clicking, dropdowns stop loading etc. I would assess therefore that this feature is very high priority, since it makes reliable continuous delivery of a sapper application nearly impossible right now. The workaround looks good - I will implement this on my application asap, since right now I've just had to turn the CDN off which is far from ideal. |
This "serving a mix of old and new" is already well solved for the JavaScript served by Sapper: hashed URLs. Maybe a good solution is to enhance Sapper, or the default configuration thereof, to also hash asset URLs? Many popular websites are served this way (with hashed asset URLs for images etc, not only JS) to prevent this kind of problem. (As part of such a solution (I don’t know if there is a good Sapper answer for this part yet, even for JavaScript URLs) is that when deploying a new version, old asset URLs must also continue to serve their old contents for a while, to support pages already running in browsers, overly enthusiastic caching layers, etc.) |
The hard-set cache header stumped me when implementing the not-too-uncommon OAuth flow, à la: Visit (Oddly, this isn't an issue in Chrome: it seems it ignores any cache when following redirects.) My hack-around (ooh, it's bad!)... ...a 'max-age=600': 'no-cache' 💥 🤠 Q: Why set a |
a fixed maxage is simply not practical for many applications, and for our upcoming release we're going to ship the sort of ugly setHeader overwrite workaround. It would be really good to get this resolved in a less hacky way. |
I think a good default would be to set the cache age to 0 for all dynamic content and used a long-lived expires header for static content with a hash in the filename. The default for dynamic content right now doesn't make sense. Sapper handles the static content it serves under
|
I just wanted to say that Sapper pages without Supporting users customising the |
@jthegedus I'm not 100% I agree with your conclusion. A static page would be defined as one whose content doesn't change between renders. If you were to have logic in your script tag which affected renders then this would not be the case. I'm very much in favour of having a globally configurable default here, with a future view to having it configurable on a per-route basis. |
@antony with regards to |
But logic in the script can also modify the SSR output as well. |
@jthegedus to clarify - |
Huh? They both run client and server. |
This particular discussion is probably best had in #1046 The confusion here makes me think the API could be more strict to better enable (support) future features and optimisations. |
@pngwn yeah sorry, my bad. Should have been sleeping not typing. @jthegedus I think the API on this is very clear (despite my confusing it further!). In fact Svelte/Sapper's SSR/CSR separation is the clearest of any of the similar frameworks. I think we should fix this issue and close this by making the header modifiable, and then further optimisation belongs in the ticket you linked. |
I raised an issue in the template to add hashes to the static filenames and provided the code to do so there. If I don't hear any objections I'll send it as a PR. |
We've removed the |
I think I mentioned this in a previous issue, but it would be nice to be able to override Sapper's built-in cache-control headers. Sometimes you want to add
public
, or sometimes you want to increase or decrease themax-age
, etc.Currently I can work around this, but it's extremely hacky:
If there's some Express/Polka-standard way for middleware to do this then I'd be happy with that; else maybe it could just be an option passed in to
sapper.middleware()
?The text was updated successfully, but these errors were encountered: