JavaScript to get around IE caching downloadable EXE's?

Discussion in 'JavaScript' started by SixSigma, Oct 29, 2007.

  1. #1
    I have a problem with my site and IE users. When I post updated versions of my setup.exe file, the users are still getting the old version. Doing a little reading, I realized that IE is caching EXE's. I had heard this was a problem with images, but I didn't know that it affected downloads as well.

    Not being much of a JavaScript dev, I put together the following code to append a random querystring variable to the end of the file name:

    
    function UpdateDownloadLinks() {
      var i;
      var linkLength;
      var linkType;
      var linkCount = document.links.length
      var randNum = Math.round((Math.random()*10000));
      
      for (i = 0; i < linkCount; i++) {
        linkLength = String(document.links[i].toString()).length;
        linkType = String(document.links[i].toString().toLowerCase()).substring(linkLength, linkLength - 3);
        if ((linkType == "exe") || (linkType  == "zip"))
          document.links[i].href += "?fid=" + randNum;
      }
    }
    
    Code (markup):
    This seemed to work for IE6, but IE7 users were complaining that the download was just "setup". IE7 stripped the ".exe" extension off the file.

    So I have several questions:
    (1) What exactly are the caching problems with IE and do they vary by version (as I suspect)?
    (2) Is there a solution to this?


    Thanks.
     
    SixSigma, Oct 29, 2007 IP
  2. ndreamer

    ndreamer Guest

    Messages:
    339
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    theres a few ways to get around it.
    1. name your program with the version number tacked on the end.
    2. send a no cache header.

    to get around your current problem you would have to make some type of serving script to send the following header.
    
    Content-Disposition: attachment; filename="setup.exe"
    
    Code (markup):
     
    ndreamer, Oct 30, 2007 IP
  3. SixSigma

    SixSigma Peon

    Messages:
    164
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks ndreamer. I'll look into the Content-Disposition option.
     
    SixSigma, Oct 30, 2007 IP