Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP "Expires" header does not work in Chrome

My system is Windows 7 x64, Chrome 20.0.1132.57 m.

In my HTTP response header, I have:

Cache-Control: public, max-age=1000
Expires: *some date*

In IE & FF, the page is cached in local, and when I try to access again by typing the URL and hit enter, no request is send and the page is displayed correctly. But in Chrome, it always send a request to the server with the following header:

Cache-Control: max-age=0

I do not want the client send a request to my server and then reply 304. I want to save the round-trip time.

like image 587
David S. Avatar asked Jul 19 '12 11:07

David S.


People also ask

What is expired HTTP header?

The Expires HTTP header contains the date/time after which the response is considered expired. Invalid expiration dates with value 0 represent a date in the past and mean that the resource is already expired.

HOW use expired header in HTML?

The expires header is an HTTP header that indicates whether it is possible to obtain information on request from the browser cache or if you need to access the server since the page option in the cache is already outdated. This header contains the date and time until the page is available in the browser cache.

What will happen if you set an Expires header to a later date say 1 day )?

When you set an expires header for a resource, such as all jpeg images, the browser will store those resources in its cache. The next time the visitor comes back to the page it will load faster, as the browser will already have those images available.

Does response header expire?

The HTTP Expires header is a response-type header, the fundamental way of controlling the caches present. The expire header contains the date and time which denotes the period where the object can stay alive.


1 Answers

Be carefull when you are testing. I noticed that in Chrome version 20 if I hit F5 to reload the page then in the network panel I see new requests. Hoewer if I place the cursor to the title bar, after the current page url, and hit enter, I get resources from cache, whitch header was set to cache.

Also its better just use the max age. Max age and Expires is the same, but in max age you specify the duration.

See this: http://betterexplained.com/articles/how-to-optimize-your-site-with-http-caching/ Method 3 and Method 4.

like image 105
Kristóf Dombi Avatar answered Sep 24 '22 10:09

Kristóf Dombi