Posted on 2/16/2009 10:02:11 PM by Justin Etheredge
I was trying to get some work done this evening on a test ASP.NET MVC website and I made what many (or all) would consider to be a rookie mistake. I created a simple form on a page and included JQuery’s javascript files in the page using a tag like this:
<script src="../../Scripts/jquery-1.3.1.min.js" type="text/javascript" />
And when I rendered the page, I ended up with nothing but a white form. Figuring that I had put something funky in the html, I rendered it in Internet Explorer. I got the same white background with no html rendering. My first thought was that something was causing cassini to crash during the request, but I wasn’t getting any errors.
So I switched over to running in IIS (which required an install since I had just switched to Windows 7), but I was still getting the exact same result. I was so confused because even when I included multiple javascript files, I could always see the javascript from the first script tag, but nothing at all after that! Argh! I checked settings, IIS logs, file attributes, permissions, everything… and you know what the problem was? I self-closed the freakin’ tag. Yeah, both Firefox and Internet Explorer totally choke on self closed script tags without saying anything. As soon as I changed the tag to this:
<script src="../../Scripts/jquery-1.3.1.min.js" type="text/javascript"></script>
It started working immediately. In fact, if I had bothered to open it up in Opera, it would have rendered just fine. Interestingly enough, Firefox is okay with self-closing script tags as long as the last script tag is not self closed. Interesting parsing behavior.
So anyways, I know I have come across this error before, and since I once again wasted a ridiculous amount of time on this; I wanted to get this up on my blog. Now I will remember it for the future and hopefully help someone else out in the process. Just don’t make fun of me too bad.