I have a website with static assets that don't change (js, images, etc). Each of these assets has the cache-control header set with the following property:
cache-control: public, max-age=31536000, immutable
However, when I reload the page I'm still seeing 200 responses from the server instead of a 304 response. The browser is indicating that the asset is being served from memory or disk cache, but it is still making the request and downloading content. This used to work before and I'm leaning towards this being a browser bug, but I'm not entirely sure.
What is discussed in comments and as mentioned by Kevin, you seems to have misunderstood conditional get request.
There are bunch of questions that you might want to get answer for:
1. Why browser is getting HTTP 200 status instead of 304?
When browser loads any document, request for static resource will go through cache handler and if resource exists in local cache, request will be server by cache handler and response will have HTTP 200 status as opposed to sending request to server.
For example, for this stackoverflow page, when I refresh the page I also see something similar in the network tab for jQuery for example.
but there aren't any request made to fetch the resource. Looking at the fiddler, there is a request to establish HTTPS connection, but nothing to fetch jQuery.
2. When will browser send conditional request?
When cache expires, user agent will send conditional get request to verify it the content is modified or not, if resource is not modified, server will send HTTP 304 response and along with it is will share new expiry date for the content.
For our jQuery example, you can send following request from postman:
and you will get following response with updated expiry date:
Without going into details, caching can be summarized as:
3. Why it was working before?
To be honest, I am not sure why it was working before. There could be multiple reasons:
Last-Modified
header for cached resource due to which conditional get request was sent from your user agent and server returned updatedLast-Modified
date on the cached resource (Expires
response header).Last-Modified
in response and so on.Reference: