Ask a Jedi: Dynamic expires with an image via ColdFusion

This post is more than 2 years old.

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 senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Edward Beckett posted on 1/14/2009 at 2:11 AM

I don't use IE ... However in developing site for folks I have to check for "browser compatibility" with Internet Destroyer ... I mean Explorer ...

In IE (Icky ...) Go to:

Tools > Internet Options > Browsing History ...

Under Browsing History Change "Check for newer versions of stored pages " to something other than "Every time I visit the web page" or "Automatically" ...

Having the setting "Every time I visit the web page" is great when you are developing a site ... but not for browsing purposes ...

Reviewing the

Comment 2 by Andy Sandefer posted on 1/14/2009 at 2:26 AM

PHP, Internet Explorer (the flickering wonder) and FARTS are ALL FREE!

Comment 3 by Seb Duggan posted on 1/14/2009 at 3:03 AM

I was looking to see if there's a way to do this using ISAPI_Rewrite, and discovered a new product from Helicon, Ape:

It's currently in beta, and I've not yet tried it myself, but it aims to emulate all the common Apache mod_ extensions, including the mod_expires which is referenced in the article Ray mentions.

So you could set up the expiry header on all images without having to serve them through the CF server...

Comment 4 by Blaine posted on 1/14/2009 at 7:38 AM

I assume the problem is in mouseovers, which is about the only time i've noticed background image problems, so I combine my hover images into one and then use CSS positioning to select which image to use. There are lots of resources out there for doing this... Its very simple and is faster since there are less round trips to the server.

Hope this helps.

Comment 5 by Eric Hoffman posted on 1/14/2009 at 9:22 AM

Ray, for those wanting to do so in IIS, can you post what you set in IIS for this? I know I just had my network guy do it, so I don't have the syntax offhand but it really helped and improved our Yslow score in that area.

Comment 6 by Raymond Camden posted on 1/16/2009 at 12:45 AM
Comment 7 by Vyacheslav posted on 1/17/2009 at 6:23 PM

Helicon Ape is released now and you can use mod_expires module to solve your problem. Also please note 2 new modules (mod_cache and mod_gzip) are added into release.
Please refer to
to get more info.