Blocked .js files keep biting me

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.

Posted 04-03-2009 10:14 PM by sergiopereira



Pedro wrote re: Blocked .js files keep biting me
on 04-06-2009 5:33 PM

When I run into an issue that proves to be with the test environment, I like to create unit tests specifically for this.  In this instance, is it possible to write an environment test that verifies none of the files are marked as blocked?  A permissions test would also be useful.  As soon as you run into an issue, you can run these unit tests and verify everything is set up correctly.

sergiopereira wrote re: Blocked .js files keep biting me
on 04-06-2009 6:50 PM


If I could remember to run said tests I would also be able to remember to check the file's properties. The tests are still a good idea, though. Makes me wonder if Visual Studio shouldn't give me a warning about this problem to begin with.

Pedro wrote re: Blocked .js files keep biting me
on 04-07-2009 1:59 PM


True, you would have to remember to push the button :)  On the other hand, this is all you would have to do.  No browsing to different folders to look at file properties and such.

VisualStudio could warn on certain things, but you would first have to tell it what to expect.  Not every web site has the same requirements regarding file permissions and the like.  I guess you would still have to specify expectations, it would just be a matter of doing in VS or the tests.

Mital Kakaiya wrote re: Blocked .js files keep biting me
on 04-14-2009 10:52 PM

Yes, it's painful to know file has been blocked by windows after so many tries, as it blocks many file types - including help files (chm) and zip files...

Suggestion for Microsoft for Windows 7:

When there is a shortcut icon, Windows displays a shortcut indicator icon in file explorer. It would be great to have a "block" indicator icon, so user knows that this file has been blocked, and it requires to "unblock" before opening it.

Sergio Pereira wrote More on blocked files
on 06-24-2010 8:39 AM

I've written about this before. You download a file to use in your web application, like a JavaScript

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)