A Minor Fix

Many thanks to Mr Zeldman for sharing the random image script I put together. (Twice in about a week, I’m starting to blush.) Shortly afterwords Charles Dietlein (who also has one) dropped an email suggesting that I seed the random number picker for users of old PHP distributions. Done, and thank you for the heads up. I still believe that letting the web server do the grunt work is the most elegant method available.

I have received several questions asking how the individual images may be cached but it still “rotates” on every reload. Well, it’s all in HTTP. The response from the PHP script is never cached because it sends a 302 Temporary Redirect header, which by specification should not be cached by the browser or caching servers. The images themselves, once served, are just like any other static file, and they are server with Etags and Last-Modified headers that allows a browser to check later if anything has changed. If the browser receives a 304 Not Changed header in response, it knows it can go on its merry way and return the image from cache. There you have it.

I had to go back and edit this post because I was dropping in and out of the editorial we. What you read really influences how you write.

2 replies on “A Minor Fix”

Speaking of those neat random images, I was going to ask you if we could put something similar on the H-Town Blogs site? I would love to have a random image from the photo gallery pop up on the page. It was on my agenda to discuss with you tonight – although now that I am thinking about it you said you had a prior commitment! Darn! I’ll just e-mail you later about it… 😀

Comments are closed.