Debugging Javascript in IE7 - how to clear your Javascript cache

Posted by Dr Nic on November 22, 2006

JavaScript first appeared in December 1995 within the Netscape browser.

131 months later and Microsoft latest attempt to provide JavaScript support in its browser is still faulty - deleting all browser files does not delete JavaScript files from your cache.

You try to develop JavaScript for IE7 and with each change you make the browser ignores it. “Delete files…” and refresh page. Nothing. “Delete all…” and refresh page. Nothing. “Delete all…” and restart browser and “Delete all…” and refresh page. Nothing.

A real “fist through the monitor” moment if there ever was one.

If you find this page via Google and you suffer the above pain, then consider this article your Support Group. “My name is Nic, I need JavaScript to work on IE7, and I have a problem.”

So did Daniel. He also had a solution. Good man, Daniel.

So, run the following Ruby script (if you use a different language, can you copy the equivalent into the comments, please, for fellow Support Group members?) to find and delete all JavaScript files in your cache.

files = ENV['USERPROFILE'] + '\\Local Settings\\Temporary Internet Files\\**\\*.js'
Dir[files.gsub(/\\\\/,'/')].each {|file| File.delete file; puts "Deleted: #{file}"}; nil

Create a script for it or just rerun that last line each time you want to clear all JavaScript in the cache.

The Support Group session is over. Coffee and cake is at the front of the room.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Zellyn Wed, 22 Nov 2006 22:54:48 UTC

    del /s “%USERPROFILE%\Local Settings\Temporary Internet Files\*.js”

  2. Zellyn Wed, 22 Nov 2006 22:55:22 UTC

    Umm, but with straight quotes.

  3. Peter Cooper Thu, 23 Nov 2006 02:55:28 UTC

    Does the CTRL+SHIFT+click refresh trick work? I’ve tended to find this is a guaranteed “definitely reload everything” trick in most browsers after one or two goes, even IE (although I don’t have IE7 to test it on).

  4. evan Thu, 23 Nov 2006 04:13:20 UTC

    If you inline all your JS when you’re in the development environment, you can bypass the “clear cache” step completely.

    You can still edit the actual .js files, but have the template inject the actual data into script tags instead of using the src attribute.

  5. Dr Nic Thu, 23 Nov 2006 07:14:59 UTC

    @zellyn - ahh, I forgot my DOS basics; thx :)

    @peter - I’ll give that a try - unfortunately my inconsistent IE7 is now happily refreshing the JS without prompting.

    @evan - ahh good point for testing the original code. I think I still need to src=”…” for dynamic data + code, but inlining would have worked for my original issues, I think.

  6. Chris Thu, 14 Dec 2006 06:56:24 UTC

    Why the hell did they get rid of “Clear Cache” button???

  7. Chris Thu, 14 Dec 2006 13:04:55 UTC
  8. Karl Mon, 01 Jan 2007 19:44:17 UTC

    …and when you are really in a heap of trouble with the cache, how about renaming the javascript file… a bit of a pain, but should guarantee that the latest and greatest is downloaded to the browser. If this works the same as it does for images, than we should be in good shape!
    (just a thought, not proven)

  9. nio Tue, 13 Mar 2007 11:59:11 UTC

    I need some help, the tags created with JavaScript that works in all the older versions of IE does not work with IE7. I’ve tried everything it just doesn’t seem to work.

    Maybe you have a solution for my problem.

  10. mel Mon, 23 Jul 2007 20:50:24 UTC

    I have had nothing but problems with ie7, glad I found this post saved me even more trouble.

  11. Stubbs Fri, 03 Aug 2007 11:51:36 UTC

    This example is for Microsoft Powershell, does the same thing and purges the js files from your cache.

    # IE7 does not delete Javascript files when you “Delete files” from within IE.
    # This is a workaround for that problem.
    function purge-js
    {
    get-childitem “$env:userprofile\Local Settings\Temporary Internet Files” -include *.js -recurse -force | remove-item
    }

  12. iPhone Sun, 10 Feb 2008 08:32:15 UTC

    Does anyone know a good javascript debugger for ie7 ?

  13. Sohbet Mon, 28 Apr 2008 06:02:40 UTC

    Why the hell did they get rid of “Clear Cache” button

Comments