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.
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
This should help you:
<meta http-equiv="cache-control" content="no-cache" />
You can also configure the static content cache mechanism through IIS; you can learn how to do so here: http://support.microsoft.com/kb/247404.
<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.
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.
There is a great article I used to read about browser caching ans caching in general :
http://www.mnot.net/cache_docs/
It explains in high details what works and what does not, what is best to do.
In summary there are a lot of ways (html tags, HTTP headers) and types of cache (browser proxy, gateways)
Send Cache-Control: no-cache to the client within the response headers.
Please specify what platform are you using to make a better response.
Related
We have a web application.
Until now we had no real cache handling strategy.
When we had a new version of certain JavaScript files, we instructed our users to clear their browser cache.
Now we want to change this.
Up to this date our starting page was "start_app.html".
In our effort to implement our cache busting strategy we want to ensure that the browser will NOT cache our starting page.
We will change the extension from ".html" into ".php".
It seems that the browser has an array of extensions, when he ALWAYS fetches a fresh copy from the web server, like "php", "asp", and so on.
Is this true and which extensions are these?
Thanks alot in advance
Please don't rely on incorrect browser behavior to not cache your page. Instead, use this header:
Cache-Control: no-cache, no-store
This page has all the details as to why that header will do what you want.
Yes, I know headers are better. But we've all dealt with that system where we want something to be cached (HTML only in this case as it's a tag) like so:
<meta http-equiv="Cache-Control" content="max-age=200" />
It does not appear to work when I test it casually. Is there any way to get a document to be cached for, say, 200 seconds without access to an .htaccess file or a programming language?
I know it's not ideal, but it's occasionally functional. I was hoping there would be a way to denote a particular directory with some sort of simple rules in the HTML cache manifest. No dice.
IE has partial (and buggy) support for using a META tag to prevent caching, but this doesn't allow you to specify a non-zero freshness lifetime.
Specifying the freshness lifetime using the Cache-Control response header is absolutely the right way to go.
Every time i update my website system UI/Jquery,
users complain that things are not working for them and that they have bugs.
Users are internet/computer dummies so they don't know how to clear the cookies or the cache of the browser, so i need to connect to each one of their computers and do it myself.
I spend lots off hours doing it and they always complain.
Some of the users use Chrome, some Firefox.
Googled and found no solution for this.
Is there any client code operation that will command the browser to clear its cache
or even pop up browser window which will ask user to confirm the clear?
Regarding cache clearing: No, there isn't.
What you can do, however, is configure your web server to correctly serve expiration and cache validity headers for your content. (How to do this depends on your web server.)
You can also use "cache busting" versioned URLs. Instead of using, let's say,
<script src="script.js">
you can "version" the URL like this:
<script src="script.js?2012-12-03-13-06">
<!-- or instead of dates any other versioning scheme you like -->
and when said script is updated, also increment/change the query parameter accordingly. This should cause browsers to consider the script as new as the URL isn't found in the cache.
document.cookie = '';
With browsers that allow entering js code in the address bar you can simply make a shortcut lets say a favourite with the following code as a url:
javascript:document.cookie = '';
If you'd like to clear cache you can use meta tags not to cache the site, though caching is conciderable.
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
I've implemented server independent eTags on my site and I'm now looking at adding expires headers to prevent most of the 304 requests.
I'm concerned about using long expiration headers since it makes it tough to force a refresh if you need to update content. And I'm also not a big fan of cluttering my code with versioning query strings like:
<link rel="stylesheet" type="text/css" href="/style.css?version=X" />
So I'm thinking about setting the expiration header to something short like 10 minutes for almost everything. This way, I only have a possible 10 minute window of stale content, yet for a normal browsing session, I'm going to stop most of the 304s. And even if they do stay longer, I'll just be serving one 304 every 10 minutes unless the content changes.
It seems pretty elegant, yet I've seen a lot of sites using the above versioning querystring method, and even google's mod_pagespeed has an option to more or less do versioning automatically, so I'm just curious if this is a solid appropach or if I've missing something that makes it impractical.
Thanks
And I'm also not a big fan of cluttering my code with versioning query strings like:
Why? No one sees it, and you can easily automate it - have your CMS or framework automatically append the file's modification time or md5 hash to the link tag.
It seems that IE6 ignores any form of cache invalidation sent via http headers, I've tried setting Pragma to No Cache and setting Cache Expiration to the current time, yet in IE6, hitting back will always pull up a cached version of a page I am working on.
Is there a specific HTTP Header that IE6 does listen too?
Cache-Control: private, max-age=0 should fix it. From classic ASP this is done with Response.Expires=-1.
Keep in mind when testing that just because your server is serving pages with caching turned off doesn't mean that the browser will obey that when it has an old cached page that it was told was okay to cache. Clear the cache or use F5 to force that page to be reloaded.
Also, for those cases where the server is serving cached content it you can use Ctrl+F5 to signal the server not to serve it from cache.
You must be careful. If you are using AJAX via XMLHttpRequest (XHR), cache "recommendations" set in the header are not respected by ie6.
The fix is to use append a random number to the url queries used in AJAX requests. For example:
http://test.com?nonce=0123
A good generator for this is the UTC() function that returns a unique timestame for the user's browser... that is, unless they mess with their system clock.
Have you tried setting an ETag in the header? They're a pretty reliable way to indicate that content has changed w3c Spec & Wikipedia
Beyond that, a little more crude way is to append a random query string parameter to the request, such as the current unix timestamp. As I said, crude, but then IE6 is not the most subtle of beasts
see Question: Making sure a webpage is not cached, across all browsers. How to control web page caching, across all browsers? I think this should help out with your problem too.
Content with "Content-Encoding: gzip" Is Always Cached Although You Use "Cache-Control: no-cache"
http://support.microsoft.com/kb/321722
You could also disable gzip just for IE6
A little note: By experience I know that IE6 will load Javascript from cache even if forced to reload the page via Ctrl-F5. So if you are working on Javascript always empty the cache.
The IE web developer toolbar can help immensely with this. There's a button for clearing the cache.