Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload vs Refresh

I have this script

<?php
header("Expires: Sat, 11 Jun 2011 00:00:00 GMT");
echo "Hello World";
?>

It just writes "Hello World" and set the cache to expire on next Saturday.

Now, when I load this page in FireFox and click on reload button, it makes a new request to server to load the page instead of just serving it from cache (I think to ensure if last-modified is still valid).

However, if I put my cursor on the address bar and press Enter, FireFox serves the contents from cache.

Why is that so? Why does in first case (reload) it makes a request to server, but in second case (refresh, I guess?) it serves from cache?

like image 934
Rizwan Sharif Avatar asked Jun 04 '11 20:06

Rizwan Sharif


1 Answers

I think the terms 'refresh' and 'reload' are basically synonymous. I see this line in RFC 2616 that describes HTTP/1.1 caching that provides a possible slight difference:

An expiration time cannot be used to force a user agent to refresh its display or reload a resource

In other words, perhaps you could say refreshing is for displays, and reloading is for resources. But since browsers' primary use for resources is display, I don't see a difference.

Here's a short writeup on the terms by a developer who has dealt with browser cache control. The terms he prefers are these:

  • load: hit Enter in the address bar; click on links
  • reload: F5; Ctrl+R; toolbar's refresh button; Menu -> Reload
  • hard reload: Ctrl+F5; Ctrl+Shift+R

(The hard reload forces the browser to bypass its cache. For Firefox, you hold down Shift and press the reload button. Wikipedia has a list of how to do this for common browsers. You can test its effect on this page.)

To answer your question about how Firefox decides when to refresh, here is how the link from above explains it:

  • load: no request happens until the cached resource expires
  • reload: the request contains the If-Modified-Since and Cache-Control: max-age=0 headers that allow the server to respond with 304 Not Modified if applicable
  • hard reload: the request contains the Pragma: no-cache and Cache-Control: no-cache headers and will bypass the cache
like image 146
Abe Voelker Avatar answered Oct 13 '22 11:10

Abe Voelker