[英]JavaScript path doesn't load on Live Server extension (VS Code)
HTML and CSS files are working perfectly on my live server. HTML 和 CSS 文件在我的实时服务器上运行良好。 But every time I lead to a.js script it will not be shown on my live server.
但是每次我引导到 a.js 脚本时,它都不会显示在我的实时服务器上。 If I try to load the.js file directly through the URL it shows "Cannot GET /line.js".
如果我尝试通过 URL 直接加载 .js 文件,它会显示“Cannot GET /line.js”。 I already tried out everything I've found on the inte.net but it's still not working.
我已经尝试了我在 inte.net 上找到的所有内容,但仍然无法正常工作。 Here are the points I checked/did:
以下是我检查/执行的要点:
Installed Code Runner安装的代码运行器
Installed Node.js = node.js system path done安装 Node.js = node.js 系统路径完成
Settings = Live Server Config = specified browser Settings = Live Server Config = 指定浏览器
"liveServer.settings.CustomBrowser": "chrome" on JSON settings "liveServer.settings.CustomBrowser": "chrome" on JSON 设置
.js file is in a separate folder and accessed via <script src="line.js"></script>
on index.html .js 文件位于单独的文件夹中,可通过 index.html 上的
<script src="line.js"></script>
访问
Chrome is set as default browser on my system Chrome 被设置为我系统上的默认浏览器
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.如果 js 文件位于单独的文件夹中,则需要在脚本标记中提供到该文件夹的确切路径,因为在当前表单中,它试图在根目录中查找 js 文件。 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.有可能在呈现 HTML 页面之前加载了 javascript 文件。 You can try adding "defer" to your script tag like this:
您可以尝试将“延迟”添加到您的脚本标签中,如下所示:
<script src="demo_defer.js" defer></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.