2

my question seems duplicate of this

but I am having a case

  • when I refresh a page with F5 then images are not getting fetched from cache instead request is going to server and server responding 304 status code(not modified)
  • but if I type a URL in address-bar or navigate page from browser back/forward button then images are coming from cache.

but I am having one doubt here why request is made for cached images to origin server on F5 (page refresh)


Nginx configuration

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
  expires 2d;
  proxy_pass http://localhost:3001;
  break;
}

Request header

===================================
GET /assets/first_banner.png HTTP/1.1
Host: localhost:3000
Connection: keep-alive
Cache-Control: no-cache
Pragma: no-cache
Accept: image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.65 Safari/537.36
Referer: http://localhost:3000/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
===================================

Response header:

===================================
HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Sun, 08 Dec 2013 20:31:06 GMT
Content-Type: image/png
Content-Length: 141498
Connection: keep-alive
Cache-Control: max-age=172800
Last-Modified: Wed, 23 Oct 2013 05:34:11 GMT
Etag: "0fc96d0218a47398d37dacca76916727"
X-Ua-Compatible: IE=Edge
X-Request-Id: 48d1ec3a24e2c0f13250ea74101f6753
X-Runtime: 0.021479
Expires: Tue, 10 Dec 2013 20:31:06 GMT
===================================
Community
  • 1
  • 1
Raghvendra Parashar
  • 3,883
  • 1
  • 23
  • 36
  • possible duplicate of [What requests do browsers' "F5" and "Ctrl + F5" refreshes generate?](http://stackoverflow.com/questions/385367/what-requests-do-browsers-f5-and-ctrl-f5-refreshes-generate) – VBart Nov 12 '13 at 21:25
  • doesn't 304 mean it fetched the content from the cache ? I assume it says that because the browsers makes a smaller request asking the server if the content changed since last time, try to confirm that with a the network inspector in your browser, the response size should be smaller – Mohammad AbuShady Nov 13 '13 at 06:32
  • @MohammadAbuShady you are right, but my question is, as we have set expire for next 30days then why browser is asking for content changed? – Raghvendra Parashar Nov 13 '13 at 09:48
  • @all, I have added request and response header also – Raghvendra Parashar Dec 08 '13 at 20:44

1 Answers1

1

When you hit F5 you tell the browser to check the webserver if the content, cached locally or not, is still valid.

If the object is expired on the webserver then the browser fetch the asset again. If the object is still valid, the local browser-cached content is used.

Auro
  • 111
  • 1
  • 3
  • have checked in Chrome browser, for cached file it is asking for content changed why?, I am also expecting to use cached copy from local, why it's not happening, does new browsers not supporting permanent cache? – Raghvendra Parashar Jan 25 '14 at 19:30