Sergio and the sigil

Blocked .js files keep biting me

Posted by Sergio on 2009-04-03

This is a tip for those working with JavaScript (and possibly other types of files) that is freely available for download. For the nth time in the last few months I spent an unnecessary amount of time trying to find a problem in my code that wasn't really there.

Windows keeps track of the files you save to your hard disk which came from the Internet. Maybe you have seen this problem when you try to open a CHM file that you downloaded and see that it opens to a blank page. The same type of thing happens with JavaScript files that you download. Let's see what happened to me today.

First I downloaded the latest version of QUnit and saved to my application's directory. I did this the usual way, as shown in the image below.

Then I proceeded to use the downloaded testrunner.js file in my HTML page, via a <script src="testrunner.js"></script> tag. When I tried to open my HTML page, I was not expecting to see the particular error shown below.

I started to look for common problems: Did I save the file in the right place? Did I spell its name right? Did I mispell the function name? Did I miss a dependency? No, no, no, and no. All looked good.

That's when I remembered that the file might have been flagged by Windows. I opened its properties dialog and, sure enough, there it was, the infuriating Unblock button.

Ah, that's easy. I just clicked it and refreshed my page. Wah-wah! Problem persists. I tried typing the .js url in the address bar and saw this 401 error message from IIS, not 404.

That told me that there was still something messed up with file access. I checked the file's permissions, comparing to an older .js file in the application. The new one did not grant access to local users, so I added Read access to local users.

Now it works. Depending on how your IIS and/or ASP.NET security is configured, you may not need this last step (e.g. if the process identity already has admin rights, in which case I salute you, brave friend.) The system at hand was a Win2008-x64 installation with the default IIS/ASP.NET settings.

This problem seems to happen to me every other week and I still did not develop the reflex to take care of it right when I download the file. On the other hand, I'm getting better at remembering about it when I see stuff like "function not defined" in an error message.