例如,我对"//unpkg.com/leaflet@0.7.7/dist/leaflet.js"and中的"//“和"/js/ui-leaflet.min.js”中的“//”感到困惑。
发布于 2019-11-25 17:49:49
资源url开头的//
是一种隐式协议,它告诉浏览器使用与当前页面相同的协议,即http
或https
。
如果你在https://www.example.org的页面上,//unpkg.com/leaflet@0.7.7/dist/leaflet.js
的脚本源将加载https://unpkg.com/leaflet@0.7.7/dist/leaflet.js
。
如果你在http://www.example.org的页面上,//unpkg.com/leaflet@0.7.7/dist/leaflet.js
的脚本源将加载http://unpkg.com/leaflet@0.7.7/dist/leaflet.js
。
/unpkg.com/leaflet@0.7.7/dist/leaflet.js
的脚本资源将意味着浏览器从隐含的域名加载脚本,即http://www.example.org
,它将转换为http://www.example.org/unpkg.com/leaflet@0.7.7/dist/leaflet.js
。如果使用不当,这可能会停止加载外部资源。这应该用于位于相同主机名的资源。
您可以在developer.mozilla.org上阅读有关URL的更多信息
https://stackoverflow.com/questions/59037369
复制