Question

I'm currently using Zend Framework and for some of the actions in various controllers it has the pragmas set for no-cache. Some of them use metatags for this and others set the headers. Is it better to set it in the headers or in the metatags? Which is a browser more apt to listen to?

Was it helpful?

Solution

HTML Meta Tags are easy to use but usually not very effective. HTTP headers give you a lot of control over how both browser caches and proxies handle your objects. Therefore, I would definitely recommend you to use HTTP headers instead of HTML Meta Tags.

Also notice that PHP Headers prevent for both proxies and browsers from caching page, as far as I know you can't prevent proxies from caching page using HTML Meta Tags.

Another thing to take into consideration, from Microsoft Support:

A page that Internet Explorer is browsing is not cached until half of the 64 KB buffer is filled. Usually, metatags are inserted in the header section of an HTML document, which appears at the beginning of the document. When the HTML code is parsed, it is read from top to bottom. When the metatag is read, Internet Explorer looks for the existence of the page in cache at that exact moment. If it is there, it is removed.

So here is the way to go in your controllers:

$this->getResponse()->setHeader('Pragma', 'no-cache', true);

You could even write a ressource plugin that does it for you in all of your pages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top