Search code examples
javascripthtmlsyntaxtoken

<!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:

https://github.com/socib/Leaflet.TimeDimension/tree/master/dist https://github.com/calvinmetcalf/leaflet-ajax/tree/gh-pages/dist

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.

Thanks


Solution

  • If you try https://github.com/socib/Leaflet.TimeDimension/blob/master/dist/leaflet.timedimension.min.js in your browser, you will get an HTML page.

    If you try https://raw.githubusercontent.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.min.js 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: https://rawgit.com/socib/Leaflet.TimeDimension/master/dist/leaflet.timedimension.min.js ).