简体   繁体   中英

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

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 inte.net 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.

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM