Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding the error "SyntaxError: expected expression, got '<'"

I just wasted a lot of time trying to figure out why Firefox and Chrome were both telling me SyntaxError: expected expression, got '<' and refusing to load the script on my webpage. It turns out the issue was because I wrote

<script src="static/js/common.js"></script>

instead of

<script src="/static/js/common.js"></script>

Now I totally understand why missing the leading slash in the path would make it unable to find the script, but c'mon, surely the javascript terminal can do a better job at giving me an error. Why not just a 404 Not Found?

What is the logical reason it would give me such a misleading error? Maybe I can learn something from this experience and feel better about that huge time-suck I just endured.

like image 272
J-bob Avatar asked May 08 '15 14:05

J-bob


1 Answers

It didn't get a 404 Not Found. The server sent back a 200 OK (which was probably a configuration error) and an HTML document which the browser attempted to parse as JavaScript.

Possibly it sent back a 302 and a redirect to the homepage which then gave the aforementioned 200 OK.

like image 150
Quentin Avatar answered Nov 18 '22 20:11

Quentin