JavaScript 路径无法在 Live Server 扩展上加载(VS Code)
HTML 和 CSS 文件在我的实时服务器上运行良好。但每次我生成 .js 脚本时,它都不会显示在我的实时服务器上。如果我尝试直接通过 URL 加载 .js 文件,它会显示“Cannot GET /line.js”。我已经尝试了在互联网上找到的所有内容,但仍然无法正常工作。以下是我检查/完成的要点:
已安装的代码运行器
已安装的Node.js = node.js系统路径已完成
设置= Live Server Config =指定的浏览器
“liveServer.settings.CustomBrowser”:JSON设置上的“chrome”
.js文件位于一个单独的文件夹,并通过 index.html 上的 访问
Chrome 已设置为我系统上的默认浏览器
感谢您的输入。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 js 文件位于单独的文件夹中,则需要在 script 标记中提供到该文件夹的确切路径,因为在当前表单中,它会尝试在根目录中查找 js 文件。脚本标签应如下所示:
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:
您的 javascript 文件可能会在 HTML 页面呈现之前加载。您可以尝试将“defer”添加到脚本标记中,如下所示:
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>