Ask a Jedi: Dynamic expires with an image via ColdFusion

George asks:

Hi Ray, I have a question. I am doing a site which is using CSS at the moment. I am interested in stopping IE7 from doing a roundtrip to the server every time to see if my images have changed. This causes a flash everytime you click from link to link even though the background image has not changed. Do, you think this PHP solution could be modified for ColdFusion and IIS:

Boy, am I the only happy to not be using Internet Explorer anymore? If you follow the link in the question above, it details a simple modification that can be made to Apache using .htaccess. George is on IIS and wants to know if he can mimic the solution provided in PHP. First off, do know you can set expiration headers in IIS as well. I’ve done that for this blog and for RIAForge as well. (And it did seem to make things quite a bit zippier!)

That being said, if you wanted to do it via ColdFusion, it is as simple a matter as using the cfheader tag. Here is a trivial example with a hard coded expiration in 2019:

<cfheader name="Expires" value="Fri, 11 Jan 2019 20:19:44 GMT"> <cfset lynn = imageRead(expandPath("./presentations/cfspry/lynn.jpg"))> <cfcontent type="image/jpg" variable="#imageGetBlob(lynn)#">

I don’t have IE here to check, but I did confirm that Firebug saw the header when the image was requested.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA