PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] Why I can't import js file inside the html file, it's problem with MIME type?

 November 08, 2022     html, javascript     No comments   

Issue

I get this error: Refused to execute script from 'http://localhost:53134/home.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. when I reload home page with following code(home.html):

<!doctype html>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <base href="/">
  <link rel="stylesheet" type="text/css" href="output.css">
  <link rel="stylesheet" type="text/css" href="style.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body class="screen">
  <div class="navBar">
    <a href='/'>Home</a>
    <a href='/wallet'>Wallet</a>
    <a href='/login'>Login</a>
  </div>
  
  <p class="letters">Home page</p>
  <script src="home.js"></script> <!-- this is a problem -->
</body>
</html>

When I use console.log('hello'); inside home.html then that is not a problem, but when I add the code in home.js then it appears to be a problem. How to solve this? and this script(home.js):

console.log('hello');

Solution

The problem was on a backend.. I've used app.use(express.static('public')); which caused wrong route for js file.. It should've been <script src="js/home.js"></script>



Answered By - Ged0jzn4
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing