I know this is actually a old thing but I really got questions about this and how it was supposed to work when it started. So I got at least these four important cache headers I can send back to the client (Last-Modified
, Cache-Control
, Expires
and ETag
)
Example situation for question 2.2:
So let's say I got some site with articles.
There might be a new article every 15 minutes to 7 days.
So I set Cache-Control
and Expires
to cache for 15 min so the client always got the newest version of it.
What I think about ETag
and Last-Modified
at the moment:
I just put some hash of the content in there and I can send the client 304
if If-None-Match
== ETag
.
I can send the client 304
if If-Modified-Since
>= Last-Modified
.
Questions
- Do I need
Cache-Control
andExpires
to support all browsers or not ? - It looks like
Cache-Control
andExpires
only tells my browser how long the content should be cached on the computer right?- So I can only use
ETag
andLast-Modified
to find out when I should send304
right? - So I could just set
Cache-Control
andExpires
to forever and just send the client the new version ifETag
orLast-Modified
changed that?- Because this works in my browser but will this work in all browsers?
- So I can only use
- Do I need
ETag
andLast-Modified
to support all browsers or not ? Pragma
looks like another cache header similar toCache-Control
, which browsers are usingPragma
and do I need it?