Page caching time, if web page expiration date is not set

How long does the browser keep a page in cache?

This is set by http cache-control headers and by meta tags inside the page.
For http headers you have to check with firebug or Chrome dev tools for response headers like:
cache-control
expires
etag
pragma
For meta tag you have to check inside the html of the page for:

<meta http-equiv="cache-control" content="....." />
<meta http-equiv="expires" content="....." />
<meta http-equiv="pragma" content="......" />

One of the most important value to see both in headers then in meta is "Expires" that declare how long a file must be taken from the browser cache avoid asking to the server again.

And so? Where is the problem about that?

There is no problem if you want to make the cache life longer but there can be a lot of problems if you want to make the caching time shorter.
If you set an expiration date to one year in the future, the browser use that page for one year avoid asking for the server about upgrades. This can be ok for some situations but, if you publish a new website, the user can see the old one until the cache expire (one year later in the worst case for our example).

What happen if is not set an expiration time for cache

Todays browser (2016) try to make hypothesis about the expiration date and they set it for us. Now, most of them take the last-modified header and do some basic arithmetics:
(Today date - "last modified date" of the page) / 10 = cache duration
So this is what happen to me:
- last-modified date of index.html: 2008 (the old webmaster place a flash website inside the home page so it is never changed since old publication date)
- Today: March 2016
- Cache duration set by the browser: (March 2016 - 2008) / 10 = 7,2 Months in the future.
Result: the new website can't be visible to users that have seen the old website until November 2016 (in the worst case).
If they do a page refresh, magically they see the new website but how to advise them to do it?

So What can we do for keep the problem under control?

As far as I know there isn't a way to force a refresh because the browser doesn't speak to the server so there isn't the opportunity for alter the behaviour.
As a best practice, always set an expires meta but not too far in the future also for pages that not change a lot.
When you take a job for make a new website in an existent domain, have a look if there are possible caching problems linked to the current website.
Put this meta tags as soon as possible (when you get the work) on the old home page for change cache behaviour to as many browser as possibile; this allows to remove caching before the new website will be published:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

After that, if there are caching problems, ask your customer to advise with a newsletter that a new website is coming and to refresh the page if users not see it.
It's a good way for marketing and valorize the new website and for let user solve this hateful caching problem theirself as much as possible :).

If you know a way for solve caching long time expiration problem comments are open!

Marco Brenna



Scrivi un commento

Aggiungi un commento

To prevent automated spam submissions leave this field empty.

Plain text

  • Nessun tag HTML consentito.
  • Indirizzi web o e-mail vengono trasformati in link automaticamente
  • Linee e paragrafi vanno a capo automaticamente.
Copyright © 2018 Marco Brenna - marcobrenna.net - Tutti i diritti riservati.
Politica sulla privacy e uso dei cookie
P.IVA 08149280961