本地调试包含协议相关 URL 的网页的提示
我想完成的任务可能有一个更好的标题,但细节应该会有所帮助。
我最近了解到将脚本的 src 路径指定为 //some.domain.com 而不是 http://some.domain.com > 或 https://some.domain.com
将导致浏览器使用用于加载页面的协议来请求脚本。当从站点加载页面时,这非常有效,但我经常在本地系统上进行调试,因此协议是 file
,当然,只要找不到资源或脚本,就会发生错误。
除了更改src路径之外,还有更好的本地调试方法吗?我想有一个代码解决方案可以检测页面何时在本地运行以及何时从域加载,但我还没有找到示例。
There is probably a better title for I'd like to accomplish, but the details should be helpful.
I've recently learned that specifying a script's src
path as //some.domain.com
rather than http://some.domain.com
or https://some.domain.com
will cause the browser to request the script using whichever protocol was used to load the page. This works great when the page is loaded from a site, but often I debug on my local system, so the protocol is file
, and of course errors occur whenever resources or scripts aren't found.
Other than changing src paths, is there a better way to debug locally? I imagine there is code solution that detects when the page is running locally versus loaded from a domain, but I haven't found examples yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
安装诸如 wampserver 之类的产品,然后您将拥有一个可以测试所有内容的本地主机网络服务器。我就是这样做的,就像魅力一样。
有类似的产品可用于 ASP 或其他非 PHP 服务器端技术(您没有指定),如果您只是做 HTML + JS 那么任何旧服务器都可以。
Install a product such as wampserver, then you'll have a localhost webserver you can test everything on. This is how I do it, works like a charm.
There are similar products available for ASP or other non-PHP server-side technologies (you didn't specify), if you are just doing HTML + JS then any old server would do.