drivetosave drivetosave - 1 year ago 93
HTML Question

<!DOCTYPE html> in JS file

I am referencing two JS files in my map.HTML header. Chrome console gives

Uncaught SyntaxError: Unexpected token <

Here is why I'm confused. When I click on the Chrome Console error message, it takes me to the Sources tab. Under Sources, it puts me on the relative JS tab, and shows code starting with < !DOCTYPE html> then continues with a ton of code that is not in my map.html file or JS file. Presumably this is generated when the JS is read?

The two JS files are:

I am opening map.HTML locally with Chrome using a simple python server using a batch file (python.exe -m http.server).

I am sure this is very basic, but it's confusing me because I reference plenty of other JS files both online and locally and I don't get this error.


Answer Source

If you try in your browser, you will get an HTML page.

If you try you will get what seams a source javascript file. But your browser may also consider it text/html, because that's what github sends in content-type header.

You can use third party sites which will serve files with appropriate content-type header, (example: ).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download