Help - Search - Member List - Calendar
Full Version: PHP Headers (caching)
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
Jure Erznoznik
I modified some of my javascript files to be PHP because I needed
translation (different languages for strings).
Of course, the files get translated fine, but I would like the browser to
keep them in cache, not reload them every single time.

Non-caching is triggered by headers Pragma, expires, etc, which I am
currently solving with this code:
<?php
session_start();
header("Content-type: text/javascript");
// Header("Expires: " . gmdate("D, d M Y H:i:s", mktime(5, 0, 0, 1, 1,
2020)) . " GMT");
Header("Expires: ");
Header("Cache-control: max-age=86400");
Header("Pragma: ");

This enables the browsers to recognise files as valid for 1 day, which is
good enough for me.

Is there a better way? How can I simply disable the Expires and Pragma
headers instead of setting them blank? I searched the manual all over but
can't find any function that would do this.

Thanks,
Jure

Philip Ronan
"Jure Erznoznik" wrote:

QUOTE
Non-caching is triggered by headers Pragma, expires, etc, which I am
currently solving with this code:
<?php
session_start();
header("Content-type: text/javascript");
//  Header("Expires: " . gmdate("D, d M Y H:i:s", mktime(5, 0, 0, 1, 1,
2020)) . " GMT");
Header("Expires: ");
Header("Cache-control: max-age=86400");
Header("Pragma: ");

This enables the browsers to recognise files as valid for 1 day, which is
good enough for me.

Is there a better way? How can I simply disable the Expires and Pragma
headers instead of setting them blank? I searched the manual all over but
can't find any function that would do this.

I don't think there's much you can do to improve cacheability when you're
using PHP sessions, because of all the dynamic data that gets added to the
search strings of every URL.

But anyway, you'll find more information on cacheability at
<http://www.mnot.net/cacheability/> and there's a cacheability assessment
tool at <http://www.ircache.net/cgi-bin/cacheability.py>

I hope that helps.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.