why we use double slash instead http

浪尽此生 提交于 2020-01-03 16:52:15

问题


I see some web pages that link javascript file to page like this :

<script async="" src="//www.googletagmanager.com/gtm.js"></script>

Why we use double slash ( // ) instead http:// or https:// from beginig absolute url ? what's different ?


回答1:


the protocol will be inherited from whichever page you're on. If your site can be on different protocols - http on the homepage, https on account pages, for example - then you won't have to worry about potentially loading "insecure content."




回答2:


The difference is that by not specifying a particular protocol, the script will load using the same protocol used to load the page itself. This has advantages when the page is accessible through more than one protocol (e.g., both http: and https:).

For more information see RFC 3986, Section 5.2: Relative Resolution of URIs.



来源:https://stackoverflow.com/questions/41204479/why-we-use-double-slash-instead-http

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!