Craig Marvelley

Software and such

Preventing Aggressive Caching of JavaScript Files With IIS7

I was playing with the new beta of Ext JS 4 the other day and noticed that sometimes the scripts were being cached, so my changes weren’t taking effect. Initially I thought this was because I’d upgraded to Firefox 4 – I use the Web Developer add-on which allows me to disable browser caching, and I’d assumed the cache setting had reverted when I upgraded. However the cache was indeed disabled, so I had to dig a little deeper.

It turns out that IIS 7 will automatically cache static resources, such as JavaScript files. While this is probably what you’d want for a default production environment it almost certainly isn’t from a development point of view, when changes are being made by the minute. It wasn’t too hard to turn this feature off, however. To do so, just do the following:

  • Open up IIS Manager
  • Optionally select the site you’re working with
  • Open the ‘Output Caching’ module
  • Select ‘Add…’ from the right hand menu
  • Enter a file extension of ‘.js’ and disable both user-mode and kernel-mode caching, click OK.

Select the ‘Output Caching’ Module

Disabling JavaScript caching

Disabling JavaScript caching

According to the IIS blog
IIS should flush the cache when files are modified; however this wasn’t the behaviour that I was seeing. I had to completely disable caching to guarantee file modifications made it to the browser.