Thomas Fuchs
Hi, I'm Thomas Fuchs. I'm the author of Zepto.js, of, and I'm a Ruby on Rails core alumnus. With Amy Hoy I'm building cheerful software, like Freckle Time Tracking and Every Time Zone and write books like
   Want me to speak at your conference? Contact me!

IE6 and the open/save download dialog

September 25th, 2005

t’s great thing for web sites and applications to be able to send files to the user and have the browser download them, instead of just displaying them (at least, this is very, very useful in the application we are developing at the moment).

This can be easily done with sending a:

Content-Type: what/not
Content-Disposition: attachment; filename=“blah.ext”

Ruby on Rails nicely wraps this with the send_file and send_data methods.

But… Internet Explorer 6 displays a dialog to the user, asking if it should open or save the file that it just downloaded. If you choose “open”, Internet Explorer was failing me with not finding the file it just downloaded and the helper application that is calling showing nice error dialogs about that.

So, I started an investigation, and found that Internet Explorer opens the helper applications with the file from it’s cache. If you send along a Cache-Control: no-cache header, Internet Explorer deletes the file from it’s cache before the helper application can open it! Needless to say, Firefox and Safari work fine, because they don’t download files to their cache, but to the download location you set.

A quick and easy workaround is just sending a Cache-Control: private header instead, so that the file stays in the cache.

With my newly acquired powers, I’ve submitted a change to Ruby on Rails, so this shouldn’t be an issue anymore.