最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - why we use double slash instead http - Stack Overflow

programmeradmin5浏览0评论

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

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

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

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 ?

Share Improve this question asked Dec 18, 2016 at 0:44 farzadfarzad 6548 silver badges26 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 17

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."

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.

发布评论

评论列表(0)

  1. 暂无评论