Today's Question:  What does your personal desk look like?        GIVE A SHOUT

Differences among Enter,F5 and Ctrl+F5 in webpage refresh

  sonic0002        2013-06-13 22:03:35       4,961        0    

When we press Enter, F5 or Ctrl+F5 to refresh a webpage, is there any difference among them? Actually it's yes, we can find the difference from the request header and response header information.

There are two cases about pressing Enter in the address bar. First if the page requested is cached and not expired in the browser, we can find the header information sent by the browser is :

Host    192.168.3.174:8080
User-Agent    Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0
Accept    text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language    zh-cn,zh;q=0.5
Accept-Encoding    gzip, deflate
Accept-Charset    GB2312,utf-8;q=0.7,*;q=0.7
Connection    keep-alive

The HTTP response status is 200 OK, however, there is no record for this request in the access.log of Nginx server, it means the request is not sent to the HTTP server since there is a cached file. The request header and response header in firebug are faked by the browser. This kind of refresh costs minimum bandwidth and takes little time.

The second case is the page is expired, now the HTTP request will be:

Host    192.168.3.174:8080
User-Agent    Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0
Accept    text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language    zh-cn,zh;q=0.5
Accept-Encoding    gzip, deflate
Accept-Charset    GB2312,utf-8;q=0.7,*;q=0.7
Connection    keep-alive
If-Modified-Since    Mon, 04 Jul 2011 10:12:40 GMT

There is one more line appended to the request header : If-Modified-Since, there is also one record in access.log of Nginx server. What happens is it will first check whether the file is modified after If-Modified-Since, and this time is determined by the last HTTP response's Last-Modified attribute, if it's not modified, then server will respond with 304 Not Modified status and browser then will read content from the cache. If it's modified, server will respond 200 OK and send the new content.

Regarding F5, the HTTP request header will be :

Host    192.168.3.174:8080
User-Agent    Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0
Accept    text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language    zh-cn,zh;q=0.5
Accept-Encoding    gzip, deflate
Accept-Charset    GB2312,utf-8;q=0.7,*;q=0.7
Connection    keep-alive
If-Modified-Since    Mon, 04 Jul 2011 10:12:40 GMT
Cache-Control    max-age=0

There is one more line Cache-Control : max-age=0 appended,it means it doesn't matter whether the file in the browser cache is expired or not, it will check on the server about the file status.

Finally regarding Ctrl+F5, the HTTP request header is :

Host    192.168.3.174:8080
User-Agent    Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0
Accept    text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language    zh-cn,zh;q=0.5
Accept-Encoding    gzip, deflate
Accept-Charset    GB2312,utf-8;q=0.7,*;q=0.7
Connection    keep-alive
Pragma    no-cache
Cache-Control    no-cache

If-Modified-Since is gone, instead Cache-Control is changed to no-cache, and also Pragma line is for compabtible with HTTP 1.0. This means we don't care abot the cache and we need a forced refresh and download the file from server directly. This kind of refresh cost the most bandwidth and takes most time.

Source : http://blog.csdn.net/yui/article/details/6584401

REFRESH  F5  CTRL+F5 

Share on Facebook  Share on Twitter  Share on Weibo  Share on Reddit 

  RELATED


  0 COMMENT


No comment for this article.