External Javascript Source File Syntax Error Code 0 Line 1 Char 1

Our maniacally thorough Web Designers found a bug on one of our Web Pages related to a Javascript file. In IE with ‘Show All Errors’ checked in Internet Options it reported blah.js syntax error code 0 line 1 char 1.

Looking into the error I determined that it only occurred on our PROD Web Server, which meant that there was no real problem with the Javascript file. Just to see if it was a cross-browser issue I loaded the offending page in Firefox and was immediately rewarded with a whole truckload of additional information via Tools -> Error Console

Lesson #1 – Debug your Web Page in Firefox. You get much better and much more debug information out of it.

The Firefox Error Console told me that the offending URL was http://www.mypage.com/scripts/blah.js and that the offending line of source code was a DOCTYPE definition, like so: !DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”

But the rest of the source file was not the blah.js file, but our Custom 404 (File Not Found) Page from the Web Server. So, looks like blah.js could not be found.

Examining the aspx page, blah.js was being loaded as an external javascript file:
script src=”/script/blah.js” type=”text/javascript”.

Now, I don’t have access to the live Web Server, but the Engies confirmed for me that there was no folder named ‘script’ in the IIS Directory for http://www.mypage.com, so naturally src=”/script/blah.js” did not exist. I asked them to edit the external script reference for blah.js to a Hotlink I knew was valid, like so
script src=”http://www.myscriptlibrary.com/script/blah.js” type=”text/javascript”.

Tomorrow, after they do it, I’ll tell you if that fixes the problem. I’ll bet you one slightly damaged Ferrett that it works.

This Condition Is Caused By…

The path to the external blah.js in the src attribute of the script tag on the aspx page was non-existent, giving a bad URL. The HTTP Request that served the script returned 404 for http://www.mypage.com/scripts/blah.js giving back our Custom 404 Page. The first line of that page is DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”. That line is not valid javascript hence the syntax error reported by both IE and Firefox.

This Stack Overflow thread, Doctype Error With Google Maps put it all together for me, many thanks to Stack Overflow User #176492 Mike Williams You are much more than a number to me.

Update 3-Mar-2010: Firebug Rocks

I’m a little closer to solving the whole puzzle now.

Using the amazingly useful Firebug I was able to inspect the HTTP Result Codes in its Net Panel. This showed me that /scripts/blah.js got a 404 on our DEV server but a 200 (OK) on our PROD Server. That 200 is not a real 200 of course, but a Soft 404.

Checking Web.Config I found that customErrors is set to On and that it returns our custom Page “custom404.aspx” for a 404 error. The first line of that page is !DOCTYPE etc. Below is a sample customErrors entry so you know what I mean. More info from Milan Negovin here at ASP.NET Resources

customErrors mode="On" defaultRedirect="~/errors/GeneralError.aspx"
error statusCode="404" redirect="~/errors/custom404.aspx" /

Didn’t check DEV Web.Config yet. I’ll bet customErrors are off or 404.aspx does not exist on that server. Double or nothinng on the Ferretts ?

And just for fun here’s Google’s list of best 404 pages.


Tags: , , , , , ,

4 Responses to “External Javascript Source File Syntax Error Code 0 Line 1 Char 1”

  1. om Says:

    Thanks for the post. The line that clicked me was ” looks like blah.js could not be found.” ….
    I had to give anonymous access to my javascript files folder.

    • baraholka1 Says:


      Nice one.
      Thanks for the alternative solution.
      Come back for another Bite anytime:-)

      – Barra

  2. Skunkjuice Says:

    I never heard so much gobble-de-gook in me life.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: