0

I'm looking for a way to force my index HTML page to be cached in the browser with a response of 200 (cached) rather than a normal 200 or 304 response.

This question is very similar to Nginx - "force" 200 cache response instead of 304.

What I have tried:

I have tried sending these headers from my server:

Expires: (some date in the future)
Cache-Control: public
Pragma: public

Or:

Cache-Control: public, max-age=3600

But neither of these get the result I need.

Example site with working HTTP caching:

https://www.mozilla.org/en-GB/

On first load of the Mozilla website, everything is returned with a standard 200 response. On a refresh, all of the resources are loaded through the local cache (and the browser network tab shows a 200 (cached) message).

The index page is sometimes loaded with a 200 OK or 304.

Mozilla screenshot

I want to know if it is possible to get my index page to load from the browser cache like the resources are on the Mozilla webpage. If it is possible, how can this be done?

harvzor
  • 2,832
  • 1
  • 22
  • 40
  • 200 is 200, what do you mean by 200 (cached)? How did you determine it’s not being cached? – Sami Kuhmonen Jun 06 '18 at 12:51
  • @SamiKuhmonen `200` and `200 (cached)` are not the same thing. Please read: https://stackoverflow.com/a/1665097 – harvzor Jun 06 '18 at 12:58
  • That talks about some plugin that shows states like that. It’s still 200 in HTTP terms. – Sami Kuhmonen Jun 06 '18 at 13:00
  • @SamiKuhmonen I'm asking if there is a way for me to force caching without making a request to the server in the first place, by using response headers. I've seen that a browser can do that with HTTP caching. The browser tends to display `200 (cached)` in this case. – harvzor Jun 06 '18 at 13:05
  • Force? No. Suggest? Yes, with the headers you’ve used. But you haven’t explained what isn’t working and you’ve determined this – Sami Kuhmonen Jun 06 '18 at 13:07
  • I have updated the question to have more thorough information (and an example). – harvzor Jun 06 '18 at 13:28

0 Answers0