I'm a developer on a website which has a server which serves HTML and another server which handles API requests. I use a CDN to cache both the HTML and API responses. I feel that it gives me all the control I need while keeping the cache settings in one place. If I make a deployment of new website version I just invalidate the cache on HTML pages and API responses at the click of one button. I can also set different cache settings per certain pages/API routes.
That being said there're cache control headers for a server to notify the client for how much time a response is valid (e.g. max-age
). I'm sure there may be use cases for the use of the headers (maybe if some extremely granular caching settings need to be applied based on some intricate business logic). Another advantage of using max-age
for example is that browser can cache a response locally. However, if a CDN allows for 100 ms HTML response I don't think it makes a huge difference if a browser goes ahead and actually performs the request.
A big downside of using cache control headers in my opinion is:
- the complexity of maintaining cache settings all over the code base (no single point of truth like a CDN dashboard).
- When a new website version is deployed it is easy to add a new version hash/id to some header in API response so that the client may be issues with "old" frontend logic interacting with "new" API logic.
I'm wondering if using cache control headers is justifiable in the scenario I described (website with HTML and API servers) and what advantages outweigh the disadvantages I described?