If any information is critical to your website and if you want to remove out of date contents and want to prevent web browsers from caching 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 3 4 | <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 the browser that the cached copy of the page is out of date and after that we have written “no-cache” so the browser will not cache the page.
no-cache with meta tag is not much feasible solution because Browser first loads the page and read meta tag and if tag did 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 ways 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 3 4 | header('Expires: Mon, 24 Feb 2004 08:21:57 GMT'); header('Pragma: no-cache'); |
The HTTP protocol gives 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.
You also like other post, see here:
To set Expire Headers using .htaccess
Browser Detection with Joomla
Comments (1)