why we use double slash instead http

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 ?

Answers:

Answer

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

Answer

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.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.