Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to tell the browser not to cache?

I have a web page that always needs to stay current. I do not want the browser to cache it. To that end, this meta tag is embedded with the page:

<meta name="Expires" content="Tue, 01 Jun 1999 19:58:02 GMT"> 

However, some browsers seem to ignore it. Chrome is particularly bad at it, though other browsers tend to do the same thing.

When I pick the page from the bookmarks bar, most of the time, it doesn't even hit the server, just loads it from cache. If I then press F5, it does go to the server and fetch a new copy.

Am I missing something simple? I thought the expires meta tag is the way it's done.

This is happening on an IIS 5.0 on Windows 2000.


Bottom line: looks like meta tags inside the HTML code pretty much do nothing. However, setting the expires tags within the HTTP does the trick nicely.

like image 506
AngryHacker Avatar asked Sep 03 '09 00:09

AngryHacker


People also ask

How do I set my browser cache to expire?

One of the way to Set cache expiration is by using . htaccess file. Below code will set expiration for it's respective file type, e.g. for CSS files expiration will be 14 days.

Does the browser automatically cache?

Every time a user loads a website page, their browser downloads the page's data to show it. Just like website servers, browsers cache most content on a page to shorten load times. So, the next time that user loads the page, most of the content is ready to go without needing to download additional data.

Why will you consider clearing my browser cache?

It is a good idea to clear your browser cache because it: prevents you from using old forms. protects your personal information. helps our applications run better on your computer.


3 Answers

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

Is really ALL you need, as stated here https://youtu.be/TNlcoYLIGFk?t=654 by Andrew Betts, elected W3C TAG member.

Using this, you will not need pragma or expires. Infact, the above will overwrite the Expires command.

like image 72
Flo K Avatar answered Oct 07 '22 09:10

Flo K


Send your expires headers using your server. Specifically, if you're using apache, look at this:

http://httpd.apache.org/docs/2.0/mod/mod_expires.html

like image 20
Paul McMillan Avatar answered Oct 07 '22 09:10

Paul McMillan


You want to send an Expires header set to a date in the past (like your Meta tag).

Expires is the most widely respected cache header, but you can also use things like Last-Modified, or Etags to get more specific control.

Meta tags are a somewhat outdated means of setting caching protocols, and most of the meta cache control properties are fairly deprecated (e.g. NO-CACHE). A lot of user agents ignore them.

like image 39
Gabriel Hurley Avatar answered Oct 07 '22 09:10

Gabriel Hurley