Reputation: 270
Currently on my HTML page I am facing a problem that it is not retrieving the latest page from server and just taking it from cache. To resolve this I have chosen the below option in IE which seems resolved my page.
Is there any way I can achieve it in HTML or JavaScript? Any tag or attribute on HTML page?
I appreciate your guidance resolving this.
Thanks, Jdp
Upvotes: 0
Views: 102
Reputation: 3371
If you have control over the page being fetched, add this tag:
<meta http-equiv="Cache-control" content="no-cache">
and the browser won't cache it.
Upvotes: 1
Reputation: 1602
If it's simply because you want to test your page and want to force a reload, CTRL + F5 should do the trick for IE and most other browsers.
Upvotes: 0
Reputation: 1081
If you know your page has lots of content that changes often, you could fetch just that content via an AJAX request to your server, while the rest of the page could stay the same. Additionally, you can add a random string to the URI you send to your server while constructing your AJAX request to make sure you bypass the browser cache:
var uri = "/fetchContent?param1=value1¶m2=value2...&rand=" + rand();
Upvotes: 0
Reputation: 2264
In PHP
, something like this would do it:
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
For more detail, go here.
Upvotes: 0
Reputation: 428
If you are serving static HTML content, then you should just change the link that refers to that page each time when you know the page should be different using a cache buster.
<a href="new_html.html?v=2">My Page</a>
Upvotes: 0
Reputation: 507
When the page loads, you could check to see if there is a query value. If there isn't, then you could reload the page with a cache buster.
I think that this would produce a poor user experience.
if you go to: www.site.com
, and it caches, going to www.site.com?cb=1
will get the page again. This is a cache buster. You can generate a random number and redirect the page to the same page with the new cache buster.
Upvotes: 0