How (not) to use HTTP Cache Part 2
How to use Browser Cache can be confusing. Here are list of example uses and how the headers should be set in order to archive it. You do not need to know the internals or how it works, you can simply put these headers in the correct places and the browser cache will be setup properly for you. Think of it as a cheat sheet for browser cache.
My previous post on how this all work is available at Part-1. It is not needed to continue this post. It will provide a in depth details about the specification and how you can cater your custom solution.
No Cache
I highly suggest not to do this. But if you just want to get the application running, get rid of the browser cache. Add the following header to either the client (request) header or server (response) header.
Cache-Control: no-store
Static assets with infinite caching
This setup will set freshness to a day. So any subsequent requests that tried to fetch the resource for a day will be served from the browser cache. Even though, the server resource change, it will not be reflected to client unless they clear the cache. This can be used for static assets of a website.
For an example: Lets take a website with an index.html
and two assets called somejs.js
and…