4 ms·
I'd be very wary of using any HTTP headers with permanent effects. They seem like a way to get easily burned by accident. For immutable caching in particular, I
by zokier 10y ago
I'd be very wary of using any HTTP headers with permanent effects. They seem like a way to get easily burned by accident. For immutable caching in particular, I'd probably try to utilize some variation of content-based addressing, eg having the url have the hash of the content.
See also: http://jacquesmattheij.com/301-redirects-a-dangerous-one-way-street http://jacquesmattheij.com/301-redirects-a-dangerous-one-way... and the related HN thread with good discussion
- mmastrac 10y agoIt's not permanent if you don't make it permanent - like the other cache-control headers, you can specify the amount of time that a resource is considered immutable. All this does is change the time period in which the browser avoids sending 304s.
- Confiks 10y agoThis might be considered similar to the DoS vector that was also present in the HTTP Public Key Pinning proposal [1]; an adversary seizing temporary control over the server can convince clients to not request a response from the server for a certain period, or in the case of HPKP request a response that cannot possibly be fulfilled. Its seems much more mundane in this Cache-Control case, but it is the same vector nevertheless. [1] https://blog.qualys.com/ssllabs/2016/09/06/is-http-public-key-pinning-dead https://blog.qualys.com/ssllabs/2016/09/06/is-http-public-ke...
- mtberatwork 10y agoYou can get burned using 301 redirects over 302 just as easily if you are not careful. But it does not mean that we should abandon using 301 redirects.
- jerf 10y agoThat's exactly what Facebook is doing: https://code.facebook.com/posts/557147474482256/this-browser-tweak-saved-60-of-requests-to-facebook https://code.facebook.com/posts/557147474482256/this-browser... But I agree that you are correct to issue this warning. It is something you need to understand before you accidentally slather that on all your content.
- benjaminjackman 10y agoI made some comments over in the "chrome version" of this thread: https://news.ycombinator.com/item?id=13492483 https://news.ycombinator.com/item?id=13492483 I agree with you that HTTP headers feel like a hack for most use cases. It would be nice to embrace the best practice of content-based addressing as an official standard rather than as an adhoc hack on top of query parameters (or whatever approach is taken). The url itself ought to convey: 1. if it's immutable 2. if possible, provide hash-based address of its content, in addition to a particular url that provides that content. (that url should eventually come to be viewed as a fallback location, the content should primarily come to be obtained by its hash). I agree and don't feel like relying on http headers is the right way to convey that a particular url is in fact immutable. It feels like that that generally belongs with the url itself not in the response to it, (for static resources atleast). Think about programming if a function was immutable, or pure, we'd mark it as such in it's type signature (e.g. @pure), where we have language support, not as additional thing it we got in the basket of crap we got after we executed it. For dynamic restful API type services (an image resize service was an example), the url still ought to be marked immutable in some fashion, but the actual hash won't be known until the function is executed once. This seems like a function memoization type problem so in that case the content hash will have to be passed along with the result. Anyhow, It would be really nice to: 1. Have these features (@pure &| content-hash = abc123) in urls usable today so that they are backwards compatible, e.g. fail right into the fallback address for all the older devices of the world. 2. Are standardized and universally intelligible and not adhoc as the approaches to content-based addressing are today, so that eventually we can get first class support for loading resources just by their hashes from the browsers themselves.
- dotancohen 10y ago> Think about programming if a function was immutable, or > pure, we'd mark it as such in it's type signature Actually, MySQL has something similar. Stored Functions can be marked as [NOT] DETERMINISTIC, to indicate that they will always return the same value given the same input. https://dev.mysql.com/doc/refman/5.7/en/create-procedure.html https://dev.mysql.com/doc/refman/5.7/en/create-procedure.htm...
- mbell 10y ago> I'd probably try to utilize some variation of content-based addressing, eg having the url have the hash of the content Fingerprinted assets with max expiration has been standard practice for years in many frameworks. However, even fingerprinted assets with max expiration are revalidated when the user hits the refresh button since historically this is what refresh has meant. The `immutable` header just allow skipping the validation.