Reputation: 9920
I'm requesting a css file over HTTP from Chrome (Version 93.0.4577.63 (Official Build) (64-bit)). The initial request looks like this:
As you can see, it has Cache-Control: no-cache
in the request.
Doesn't this mean it first has to check with the server whether or not its version of the css file is up to date?
In which case it should get a 304 Not Modified
(assuming the file hasn't been modified) on the next request?
Here's the request/response when I did a refresh of the page:
Why am I getting a 200 (from disk cache)
and not a 304 Not Modified
?
The issue is that some users of this website are getting an out of date version of the css file.
I suspect it's because the cached version is being returned before being revalidated with the server which is what I thought no-cache
was meant to do.
Update:
I'm not sure why, but when I did refresh again, I got fewer headers in the request:
I didn't have the Disable cache button checked
Upvotes: 4
Views: 12203
Reputation: 683
If you want to solve 200 (from disk cache) issue here is the solution
Add these headers to your request call
[
'Cache-Control' => 'no-cache, no-store, must-revalidate',
'Pragma' => 'no-cache',
'Expires', 0
]
From My understand the request saving the response in browser cache that's why it's returning the 200 (from disk cache)
and it's return the old loaded data
Note: I faced same error for file download api. wher First time it's return 200 but after that same api getting
200 (from disk cache)
My Solution was for api download response:
return response()->download($attachment->getPath(), $attachment->name . '.' . $extention, [
'Cache-Control' => 'no-cache, no-store, must-revalidate',
'Pragma' => 'no-cache',
'Expires', 0
]);
But maybe in your case this isn't right answer but so far this is header issues
Upvotes: 0
Reputation: 31
Do you have the cache disabled in the devtools?
In Firefox, I get 304 only when the cache is not disabled.
Upvotes: 0