Web caching is tricky.
In this set of notes I aim to create a quick reference guide to caching. I'll include little snippets of configs and notes on browser / platform quirks. It will get more complete over time.
Entity tagging causes a hash to be computed and stored for every file resource. The hash will naturally be unique to that resource. Browsers that are properly interfacing with a backend using etag's will cache the resource and the last etag. Next time the etag is requested, the browswer will check if the etag has changed before choosing whether to use the copy from local cache or pull another from the server.
ETag's are almost perfect, except they result in an additional round trip per resource to the server. Even with HTTP2, requests are pretty expensive. This means that filename hashing is a far better choice for large sets of files that will randomly change (like code) and traditional caching rules are better for static files that simply don't change (like images).
etag on;
add_header 'Cache-Control' 'no-cache';
This is something of an informal term for this practice, which I will use here until I do proper further research. Filename hashing is possible when a bungler bundler or some other build step is included with the deployment of web code. Hashes are inserted into the filename after the name and all references are re-linked so that the corpus of code is all internally consistent.
This caching method is very powerful, because "cache-forever" headers can be slapped on these resources and the browser never spends time round-tripping a bunch of etag checks. The instigating HTML file must still use etags, of course, because something must act as the gateway into the code set. But all js, css, etc. files will only ever be downloaded once-per-change.
I have yet to actually try this out. My understanding of the 'build step' is progressing slowly. I hope to get around to this soon.
With this, I refer to classical means to set cache timeout on a resource. There are a thousand guides on this. I will extract notes on this in the future.