Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome isn't loading my js file [duplicate]

My page is very basic

<!DOCTYPE html>
<html>
  <head>
    <title>Title</title>
  </head>
  <body>
    <h1>Title</h1>
    <canvas id="can"></canvas>
    <video autoplay id="vid" style="cursor:pointer"></video><br>
    <script type="application/javascript;version=1.7" src="8bit.js"></script>
  </body>
</html>

It loads the JavaScript Firefox, but does not in Chrome.

If I copy and paste the contents of the JavaScript file into the console in Chrome, then it runs fine.

Why doesn't it load from the script tag in Chrome?

like image 955
Matt Ellen Avatar asked Aug 17 '15 12:08

Matt Ellen


1 Answers

Essence from the MDN about let keyword:

The keyword let is supported in Chrome only for testing purposes only in the Console and not in the normal flow. Chrome doesn't support let but Firefox does.

Replace the following:

<script type="application/javascript;version=1.7" src="8bit.js"></script>

With:

<script type="text/javascript" src="8bit.js"></script>

Chrome makes a strict decision on type attribute. So please use that carefully. Only for Firefox, this is valid:

Only available to code blocks in HTML wrapped in a <script type="application/javascript;version=1.7"> block (or higher version). Beware, however, that as this is a non-standard feature, this will most likely break support for other browsers. XUL script tags have access to these features without needing this special block.

Workaround for Chrome:

To enable these special keywords, add the following code on the top of the script block:

"use strict"; 
like image 91
Praveen Kumar Purushothaman Avatar answered Sep 22 '22 20:09

Praveen Kumar Purushothaman