简体   繁体   English

GO-HTML文件无法加载外部JS文件

[英]GO - html file can't load external js file

I have a GO project which has UI written by html. 我有一个GO项目,其中包含用html编写的UI。 In HTML file, I have written javascript, and I can install GO and load the UI successfully. 在HTML文件中,我已经编写了JavaScript,并且可以安装GO并成功加载UI。

The problem is when I move those javascript code to an external file, and include it: . 问题是,当我将这些javascript代码移动到外部文件并包含它时:。 I only can build GO, but when load the UI, it has error 404 Not Found which is "myscripts.js" file. 我只能构建GO,但是在加载UI时,它会显示错误404 Not Found,即“ myscripts.js”文件。 The weird thing is on its header of error: Remote Address:127.0.0.1:8080 Request URL: http://localhost:8080/subscribe/myscripts.js Request Method:GET Status Code:404 Not Found 奇怪的是它的错误标头上:远程地址:127.0.0.1:8080请求URL: http:// localhost:8080 / subscribe / myscripts.js请求方法:GET状态码:404未找到

Please help, I can't find any answer yet for this 请帮忙,我目前找不到任何答案

That's normal if you only define handler for your endpoints. 如果仅为端点定义处理程序,那是正常的。

You should add to your router the http.FileServer handler pointing to the directory that store your project files. 您应该将指向存储项目文件目录的http.FileServer处理程序添加到路由器。

Additionally, think about the <base> that to define the root of your relative links, which will prevent errors such as path nesting. 此外,请考虑用于定义相对链接根目录的<base> ,这将防止诸如路径嵌套之类的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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