Home > Net >  JavaScript path doesn't load on Live Server extension (VS Code)
JavaScript path doesn't load on Live Server extension (VS Code)

Time:03-02

HTML and CSS files are working perfectly on my live server. But every time I lead to a .js script it will not be shown on my live server. If I try to load the .js file directly through the URL it shows "Cannot GET /line.js". I already tried out everything I've found on the internet but it's still not working. Here are the points I checked/did:

Installed Code Runner

Installed Node.js = node.js system path done

Settings = Live Server Config = specified browser

"liveServer.settings.CustomBrowser": "chrome" on JSON settings

.js file is in a separate folder and accessed via <script src="line.js"></script> on index.html

Chrome is set as default browser on my system

Thanks for your inputs.

CodePudding user response:

If the js file is in a separate folder, you need to provide the exact route to the folder in the script tag, since in the current form it is trying to find the js file in the root directory. The script tag should look like this:

<script src="FOLDER_NAME/line.js"></script>

CodePudding user response:

It's possible that your javascript file is being loaded before the HTML page is rendered. You can try adding "defer" to your script tag like this:

<script src="demo_defer.js" defer></script>

  • Related