[thelist] Caching of external javascripts

Tony Light TonyLight at blueyonder.co.uk
Thu Nov 14 05:13:00 CST 2002


On Wed, 13 Nov 2002 22:07:25 +0000, Jim Dabell kindly gave the following
advice....

> The caching of objects through http is controlled with http headers.
> Usually php/asp/etc automatically set these to prevent caching.  Check the
> http headers returned when you request these files.

To attempt to solve my original problem, which was...

> > If we include an external javascript in an ordinary html page (i.e.
using
> > <script src="blah.js"></script>) then IE 5+ and Netscape 6 appear not to
> > cache that script, while Opera 5+ does cache it.

This got me all excited (yes, I lead a sad, sad life) so I set out to
identify the HTTP headers involved.
By SSH'ing into the server and using Lynx (with -mime_header option) I was
able to see the headers sent when I specifically requested the external
javascript directly.... No headers at all to do with cacheing.  Excitement
mounts - this looks good.

OK I thought, lets create some.  As this javascript is actually being
generated dynamically using PHP (i.e it is a .php file, but the content it
returns is javascript) it was a breeze to generate a handful of headers that
according to the PHP manual should stop even the most retentive browser
hanging onto the file. Excitement builds......

Checking with Lynx revealed the promised headers. Excitement reaches fever
pitch.... I fire up Opera 6, open my test page.... I can hardly bear it ....
back to IE5, make a change to the script, load it up to the server... Back
to Opera, hit refresh... Bite fingers, cos finger nails all gone now....
rats rats rats - no joy.  What an anticlimax.

The headers appear to make no difference to any of the browsers that I can
easily test on.  Only Opera (5 and 6) of the mainstream browsers on Windows
caches the file.  Looks like we might be near the end of the road on this
one.  Still, thanks for the suggestions and for making me learn a bit about
HTTP headers.

One lingering doubt - which hopefully someone can comment on ....
Are the headers sent when the file is requested directly actually the same
as those sent when the file is included as an external javascript? I don't
know how to check the latter situation.

Regards,
    Tony




More information about the thelist mailing list