To prevent caching in web browser
If any information is critical to your web site and if you want to remove out of date contents and want to prevent web browsers to cache your page from first place.
Solutions
There are two possible ways with that we can solve this problem
- With use of HTML meta tag.
- With HTTP headers
Let’s have a look of both ways:
1. With use of HTML meta tag.
The most useful and basic way to prevent page caching is HTML meta tag.
SYNTAX:
|
1 2 |
<meta http-equiv="expires" content="Mon, 24 Feb 2004 08:21:57 GMT"/>
<meta http-equiv="pragma" content="no-cache" /> |
With the inserting a date we can tell browser that the cached copy of page is out of date and after that we have write “no-cache” so the browser will not cache the page.
no-cache with meta tag is not much feasible soution because Browser first load the page and read meta tag and if tag was not get when page was first requested by browser,browser will keep cached copy as original.
let’s look at the alternative solution.
2.Using HTTP Headers
One of the better way is to use the HTTP protocol itself with the use of PHP header function which is same as the two HTML meta tags given above.
|
1 2 |
header('Expires: Mon, 24 Feb 2004 08:21:57 GMT');
header('Pragma: no-cache'); |
The HTTP protocol give guarantees that no web browser or proxy server will cache the page, so users will always receive the latest content.we can say this is the best way to ensure a page is not cached. But for some cases,The Cache-Control and Pragma headers will catch content and expire doesn’t work like if the date is set incorrectly in user’s machine.








no-store will truly not store in browser. we recently ran into a problem w/ no-cache not executing javascript that needed to be run on page load