脚本标签中“ //”和“ /”的含义是什么?

时间:2019-11-25 17:41:09

标签: html angularjs leaflet

例如,我对理解“ //unpkg.com/leaflet@0.7.7/dist/leaflet.js”中的“ //”和理解“ /js/ui-leaflet.min”中的“ /”感到困惑。 js”

1 个答案:

答案 0 :(得分:1)

资源网址开头的//是一个隐式协议,它告诉浏览器使用与当前页面相同的协议,即httphttps

如果您在https://www.example.org的页面上,则脚本//unpkg.com/leaflet@0.7.7/dist/leaflet.js的脚本src将加载https://unpkg.com/leaflet@0.7.7/dist/leaflet.js

如果您在http://www.example.org的页面上,则脚本//unpkg.com/leaflet@0.7.7/dist/leaflet.js的脚本src将加载http://unpkg.com/leaflet@0.7.7/dist/leaflet.js

/unpkg.com/leaflet@0.7.7/dist/leaflet.js的脚本src表示浏览器从隐式域名(即http://www.example.org)加载脚本,该域名将转换为http://www.example.org/unpkg.com/leaflet@0.7.7/dist/leaflet.js。如果使用不当,可能会停止加载外部资源。这应该用于位于相同主机名的资源。

您可以在developer.mozilla.org

上了解有关URL的更多信息。