Fun With HTML Script Tags

Writing

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.

Loved the article? Hated it? Didn’t even read it?

We’d love to hear from you.

Reach Out

Comments (6)

  1. @Liam I wish I could have found that the other day, but of course google can’t find something when you are looking in the wrong place! 🙂

    @Marwan Yeah, bizarre rendering bug. I wonder why it is hard for browsers to pick up the mistake and display an error.

  2. I made this mistake too. I run the w3c validator once in a while to see if some more nasty tagging sneaked in my views.

  3. This is the worlds suckiest browser bug ever! This has happened to me a few times and I actually solved this problem for another dev on my team the other day!

Leave a comment

Leave a Reply

Your email address will not be published.

More Insights

View All