489

I read that when you don't have access to the web server's headers you can turn off the cache using:

<meta http-equiv="Cache-Control" content="no-store" />

But I also read that this doesn't work in some versions of IE. Are there any set of <meta> tags that will turn off cache in all browsers?

Rob
  • 14,746
  • 28
  • 47
  • 65
leeand00
  • 25,510
  • 39
  • 140
  • 297
  • 1
    a combination of bobince and dpb's answers is your best bet. covers all bases. – nickf Aug 27 '09 at 13:43
  • 2
    http://www.i18nguy.com/markup/metatags.html On this site is written to preferable deactivate caching in HTTP, so that the site isn't stored on intermediate servers. Thought it might help someone. – Bodo May 28 '15 at 06:25
  • For those struggling with back button and "re-opening closed tab" caching as I am, have a look at [this answer](http://stackoverflow.com/a/19196020/993683) from another question. It's hacky, but no header-based solution was working for me and for my purposes this little JS snippet is great (easy to convert to plain JS). –  Jan 31 '17 at 09:12
  • 1
    The answers here are all sad. I would add my own, but this is closed. According to MDN: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control you do in fact most likely want to use `` as in the question. – Andrew Apr 19 '20 at 21:40
  • Note that the [](https://html.spec.whatwg.org/dev/semantics.html#the-meta-element) tag does not use and does not need a closing slash and never has in any HTML specification. – Rob Mar 12 '23 at 18:57
  • @Rob Doesn't need a slash anymore. In XHTML it does require a slash. – leeand00 Mar 21 '23 at 22:24
  • @leeand00 In HTML, it **NEVER** needed a slash. In fact, in some cases, it can cause problems. And the topic is HTML, not XHTML. – Rob Mar 22 '23 at 00:59
  • @Rob Well it wasn't when I wrote the question. It was written in XHTML. – leeand00 Mar 22 '23 at 01:29
  • 1
    Then I will add the tag for you. – Rob Mar 22 '23 at 07:12

6 Answers6

748

For modern web browsers (After IE9)

See the Duplicate listed at the top of the page for correct information!

See answer here: How to control web page caching, across all browsers?


For IE9 and before

Do not blindly copy paste this!

The list is just examples of different techniques, it's not for direct insertion. If copied, the second would overwrite the first and the fourth would overwrite the third because of the http-equiv declarations AND fail with the W3C validator. At most, one could have one of each http-equiv declarations; pragma, cache-control and expires. These are completely outdated when using modern up to date browsers. After IE9 anyway. Chrome and Firefox specifically does not work with these as you would expect, if at all.

<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" />

Actually do not use these at all!

Caching headers are unreliable in meta elements; for one, any web proxies between the site and the user will completely ignore them. You should always use a real HTTP header for headers such as Cache-Control and Pragma.

Liam
  • 27,717
  • 28
  • 128
  • 190
  • 1
    There's no special reason the third tag is in the lower case is there? – Matthew Lock Oct 12 '09 at 01:25
  • No special reason. Although you have to consider other things such as your DOCTYPE declaration, or maybe using HTML vs XHTML. –  Oct 14 '09 at 05:53
  • 244
    More explanation would be nice. Why the repeated cache-control and expires? Why do you need all of these? What's so special about 1980? What's the difference between pragma:no-cache and cache-control:no-cache? More explanation would be nice. – Bennett McElwee Sep 10 '12 at 23:36
  • 1
    Yes, explanation would be nice. Since it feels redundant to throw all these in. E.g. I only need it to work in Google Chrome, what is the minimum to get it working with that browser? – Ciantic Jan 03 '13 at 10:27
  • 18
    Not 100% sure on this, but I think the repeats are intended to handle different browsers. – Andrew Hagner Jan 09 '13 at 18:06
  • 11
    Closest I found to an explanation: http://www.i18nguy.com/markup/metatags.html – Andrew Hagner Jan 09 '13 at 21:40
  • 1
    Like css browsers dictate how they want to interpret meta tags. If it doesn't like it, it may ignore it. having the duplicate tags covers your bases. the expires set to 1980 is just an arbitrary old date for those browsers that want a date. I was just having issues with FF and the above works great. – Dan Doyon Feb 07 '13 at 19:36
  • 4
    Does not validate with W3C validator "Bad value cache-control for attribute http-equiv on element meta." "Bad value expires for attribute http-equiv on element meta." "Bad value pragma for attribute http-equiv on element meta." – Michael K Feb 08 '13 at 17:18
  • 34
    Sometimes we need to break some Validator rules in order to make things work on all browsers. – Axel Advento Jul 01 '13 at 00:41
  • 29
    The list is just examples of different techniques, it's not for direct insertion. If copied, the second would overwrite the first and the fourth would overwrite the third because of the http-equiv declarations AND fail with the W3C validator. At most, one could have one of each http-equiv declarations; pragma, cache-control and expires. – StrangeDucks Nov 07 '13 at 19:38
  • Doesn't work in IE10(8) for me – Constantine Gladky Mar 31 '14 at 13:40
  • you need this code for iOS 8 Safari when your page has ajax loaders. – karantan Dec 01 '14 at 14:57
  • @leeand00 why did you link back to this question? – Paul May 29 '15 at 17:00
  • Should explain why you need all those meta tag, which one adds supports for which browser – Matias Fernandez Martinez Jun 10 '15 at 15:42
  • 2
    New chrome browser does not work as expected with these tags. – theB3RV Dec 14 '15 at 20:34
  • 1
    I'm using this but in Firefox, it still caches and then after a few minutes or so, it'll send a condition request. What's that all about?! – ianbeks May 20 '16 at 12:29
  • Its not clearing cache of my browser. is there any other way? – Dr. Piyush Dholariya Jun 02 '16 at 07:13
  • 3
    Does not work, Chrome. – 3xCh1_23 Jan 09 '17 at 17:40
  • "Real HTTP header for headers " ???? So - how is hat an answer if you do not provide clarity of what this is??? –  Jul 06 '18 at 00:29
  • >"Do not blindly paste this!" >Former devs at my company: proceeded to do just that – Tiramonium Apr 23 '21 at 17:39
84

According to Independent Security Evaluators' great case study on the industry-wide misunderstanding of controlling caches, only Cache-Control: no-store is recognized by Chrome, Firefox, and IE. IE recognizes other controls, but Chrome and Firefox do not.

katzbatz
  • 332
  • 2
  • 16
Paul
  • 857
  • 6
  • 2
  • 5
    I found that Chrome responds better to Cache-Control: no-cache (100% conditional requests afterwards). "no-store" sometimes loaded from cache without even attempting a conditional request. Firefox responds better to "no-store" but still sometimes loads from cache if you reload immediately afterwords. What a mess! – ianbeks May 20 '16 at 12:45
25

It doesn't work in IE5, but that's not a big issue.

However, cacheing headers are unreliable in meta elements; for one, any web proxies between the site and the user will completely ignore them. You should always use a real HTTP header for headers such as Cache-Control and Pragma.

bobince
  • 528,062
  • 107
  • 651
  • 834
9

pragma is your best bet:

<meta http-equiv="Pragma" content="no-cache">
KJ Saxena
  • 21,452
  • 24
  • 81
  • 109
  • 9
    ...this is old, so presumbably your suggestion is that this is because in newer implementations this will typically be interpreted as the cacheing header cache-control: no-cache. So actually you'd be better to use the more modern – Chris Halcrow Sep 14 '13 at 21:53
8

I noticed some caching issues with service calls when repeating the same service call (long polling). Adding metadata didn't help. One solution is to pass a timestamp to ensure ie thinks it's a different http service request. That worked for me, so adding a server side scripting code snippet to automatically update this tag wouldn't hurt:

<meta http-equiv="expires" content="timestamp">

Kathir
  • 1,212
  • 15
  • 25
-5

Try using

    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="-1">
orf
  • 131
  • 1
  • 1