I need to load a JavaScript (jQuery plugin) in an HTML file. But it doesn't seem to be working. This is running on Angular-CLI server (ng serve) Here's the HTML.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<base href="/">
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="./test.js" type="text/javascript"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>Loading...</app-root>
</body>
</html>
I get this error:
Refused to execute script from 'http://localhost:8080/test.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
I found this question, where the solution seems to be correcting the type
attribute, but that didn't fix it for me. I tried text/javascript
and application/javascript
.
What do I need to do here?
EDIT: The network console shows a 404 error for the script. Says the request has no response data available. Content type says text/html; charset=utf-8
NOTE: I originally posted this as a more minimal example than my actual code, as I didn't think it had to do with Angular CLI server. That may be the case, so I restored my example to the actual code I have.
public
folder so I corrected the src link to point like this/path/test.js
and it worked fine for me. To test your script, simply copy that url into your browser and if it returns nothing your path script is incorrect.