Jure Erznoznik
Jun 20 2005, 06:23 AM
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
Jun 20 2005, 07:25 AM
"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/