Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Pragma Header? Caching pages.. and IE

So I am sending a header in php to cache my page (this integrates into our "CDN" (contendo/akamai) as well). I always use this pragma: cache header, I've seen various examples use it as well; however, I just checked fiddler to test traffic for this .net application we developed and it says:

Legacy Pragma Header is present: cache !! Warning IE supports only an EXACT match of "Pragma: no-cache". IE will ignore the Pragma header if any other values are present. ... 

I suppose that is ok. The rest of the response seems fine and to my specs. Here is my code:

function headers_for_page_cache($cache_length=600){     $cache_expire_date = gmdate("D, d M Y H:i:s", time() + $cache_length);     header("Expires: $cache_expire_date");     header("Pragma: cache");     header("Cache-Control: max-age=$cache_length");     header("User-Cache-Control: max-age=$cache_length"); } 

The question is does this matter? What does the pragma header even do? Do I need it? I checked the HTTP header spec documentation and it said it is implementation specific and the only Pragma that is enforced is "Pragma: no-cache".

Is this the best choice of headers to cache for a specific amount of time?

like image 677
Parris Avatar asked Aug 16 '12 18:08

Parris


People also ask

What is the Pragma header?

The Pragma HTTP/1.0 general header is an implementation-specific header that may have various effects along the request-response chain. This header serves for backwards compatibility with the HTTP/1.0 caches that do not have a Cache-Control HTTP/1.1 header.

What is Pragma no-cache header?

"The Pragma: no-cache header field is an HTTP/1.0 header intended for use in requests. It is a means for the browser to tell the server and any intermediate caches that it wants a fresh version of the resource, not for the server to tell the browser not to cache the resource.

How do you use Pragma headers?

To check the Pragma in action go to Inspect Element -> Network check the header for Pragma like below. Pragma header is highlighted. Browser Compatibility: The browsers compatible with Pragma header are listed below: Google chrome 6.0 and above.

What does Cache-Control header do?

What is the Cache-Control Header. Cache-control is an HTTP header used to specify browser caching policies in both client requests and server responses. Policies include how a resource is cached, where it's cached and its maximum age before expiring (i.e., time to live).


Video Answer


1 Answers

In a very simplified form, Pragma:no-cache or Pragma:cache are now "almost" obsolete ways of passing caching instructions to client implementations, specifically browers and proxies. The way the client implementation responds to Pragma headers vary which is why the specification says it is implementation specific.

The more modern way of Cache-control is what you can safely depend on, as almost all client implementations follow it rigidly.

Also, if you have both Cache-control and Pragma set for the same instruction, say caching, then Cache-control takes precedence.

This is an excellent article about everything related to Caching and I think it makes a very interesting and useful read: http://www.mnot.net/cache_docs/

like image 109
raidenace Avatar answered Sep 23 '22 01:09

raidenace