I have a page that loads a lot of images, css and javascript. I've added a far future Expires header and set Cache-Control to public on these external dependencies so they should be cached. But every time I do a Post/Redirect/Get chrome tries to load these again. This behavior is very similar to reloading the page. I've added ETags and handle the If-None-Match header which helps a bit, but it still generates too many useless requests.
How do I tell chrome and safari to get the files from cache?
chrome NOK
safari NOK
firefox OK
ie OK
Also see Full page reload on Post/Redirect/Get ignoring cache control on the google support forum.
Clarification:
I don't want the browser to request image1.png
twice. It should be cached.
200 GET page1.html
200 GET image1.png (Cache-Control: public, Expires and ETag)
302 POST action.asp (form submitted from page1.html, redirects)
200 GET page2.html
304 GET image1.png (If-None-Match)
Example:
I've created a simple example to illustrate the problem.
Headers:
The headers I send with the image are:
HTTP/1.1 200 OK
Date: Fri, 18 Jun 2010 11:30:22 GMT
Server: Apache
Cache-Control: public, max-age=86400
Expires: Sat, 19 Jun 2010 11:30:24 GMT
Etag: "123"
Content-Length: 866
Content-Type: image/png
Which should make it cached for 24 hours. There is no Vary: * or anything like that.
Update: This behavior is now also present in Safari Mobile on iOS 4. A horible regression in page-load speed.
Update: There is a bugreport about this issue in the webkit bugzilla. Bug 38690 - Submitting a POST that leads to a server redirect causes all cached items to redownload
Update: The problem persists on iOS 4.0.1
Update: The problem persists on iOS 4.1
Update: The problem persists on iOS 4.2
Update: The problem persists on iOS 4.2.1 and in Chrome from version 6 till 9.
Update: There is a bugreport about this issue in the Chromium project. (you can star it to show you care) Issue 68621: Post/Redirect/Get ignoring cache instructions
Update: The problem persists on Chrome from version 6 till 10. It is now a 9 months old bug.
Update: The problem is fixed as of 2011-03-21 19:33:07 PST. This is reflected in the behavior of chrome 12 (canary).