[thelist] How to avoid caching javascript vars

Christian Heilmann codepo8 at gmail.com
Mon Jun 26 09:01:44 CDT 2006

> My question is, how can I make sure that the browser will not use any
> pre-cached value of these variables, and that it will always load the
> correct picture? Whenever I make any changes to those I need to reload
> the page
> a few times or even close the browser and reopen it again. In one
> occasion
> IE made me even restart my computer to notice the changes.

Here are some tips that helped me _a lot_ when it comes to galleries

1) Don't rely on filenames
2) If you can, use the server to read and define the number of images
(read the folder content, filter out anything but jpg|gif|png - voila
- list of images)
3) IE + caching = urgh (for example with some proxies MSIE will not
trigger imageObject.onload once it has been cached - you need a
bespoke property to test instead).

If you still want to go this route, create the JavaScript via PHP (by
writing it out and preceeding it with a JS header and a expiry date in
the past).

Chris Heilmann
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/
Binaries: http://www.onlinetools.org/

More information about the thelist mailing list