Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome browser is not sending if-modified-since header to server

I have these headers being sent to the client by the server:

Cache-Control:private Connection:keep-alive Content-Encoding:gzip Content-Type:text/html Date:Sun, 27 Nov 2011 11:10:38 GMT ETag:"12341234" Set-Cookie:connect.sid=e1u...7o; path=/; expires=Sun, 27 Nov 2011 11:40:38 GMT; httpOnly Transfer-Encoding:chunked last-modified:Sat, 26 Nov 2011 21:42:45 GMT 

I want the client to validate that the file hasn't changed on the server and send a "200" if it has otherwise a "304".

Firefox sends:

if-modified-since: Sat, 26 Nov 2011 21:42:45 GMT if-none-match: "12341234" 

Why isn't the chrome sending the same on a refresh of the page? I'm after the behavior that .Net has running:

context.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate) 
like image 681
Asken Avatar asked Nov 28 '11 09:11

Asken


People also ask

What is if modified since HTTP header?

The If-Modified-Since HTTP header indicates the time for which a browser first downloaded a resource from the server. This helps determine whether or not the resource has changed since the last time it was accessed.

What HTTP status code means that the requested file was found but has not changed since date provided in the IF modified since header?

If the status of a particular resource is 304 Not Modified, this means that the file has not changed and there is no need to download it again.

What is the purpose of the if modified since field in a HTTP GET request message chegg?

To allow the server to indicate to the client that it (the client) should cache this object.


2 Answers

After spending half a day on this yesterday, I tracked down what was causing the issue for me. So long as you have the Chrome object inspector/Client Debugger/Network monitor/Thing that pops up when you hit F12, Chrome will not send cache request headers. Period. (update: in newer versions of Chrome, there is a checkbox "Disable cache"). Even if you don't have the "network" tab open (ex: have the javascript console open), this checkbox still disables all cacheing.

Its sad, because debugging this from the client side obligates you to leave the network panel open to see what headers are being sent and received, and what codes are being returned. Without the network panel open, there is no way to know if your content is being cached from the client side.

If you dig into your server access logs, you will notice your server returning 304s(Cached Content) the minute you close the debug window on your Chrome client. Hope this helps.

Chrome 24.0.1312.57

like image 147
Mark Avatar answered Sep 18 '22 14:09

Mark


I found one answer to this behaviour when using HTTPS, thought I'd share what I found. You do not specify if you are requesting via HTTP or HTTPS.

"The rule is actually quite simple: any error with the certificate means the page will not be cached."

https://code.google.com/p/chromium/issues/detail?id=110649

If you are using a self-signed certificate, even if you tell Chrome to add an exception for it so that the page loads, no resources from that page will be cached, and subsequent requests will not have an If-Modified-Since header.

like image 40
Neek Avatar answered Sep 18 '22 14:09

Neek