Reputation: 654
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 ?
Upvotes: 14
Views: 4030
Reputation: 234795
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.
Upvotes: 5
Reputation: 3577
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."
Upvotes: 17