//www.google-analytics.com/analytics.js和https://www.google-analytics.com/analytics.js之间的区别

问题描述:

我在阅读https://developers.google.com/analytics/devguides/collection/analyticsjs/,这是他们提供的JavaScript跟踪代码片段://www.google-analytics.com/analytics.js和https://www.google-analytics.com/analytics.js之间的区别

<!-- Google Analytics --> 
<script> 
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new 
Date();a=s.createElement(o), 
m=s.getElementsByTagName(o) 
[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
})(window,document,'script','https://www.google- 
analytics.com/analytics.js','ga'); 

ga('create', 'UA-XXXXX-Y', 'auto'); 
ga('send', 'pageview'); 
</script> 
<!-- End Google Analytics --> 

在我的实现方式之一,我对此不是https://www.google-analytics.com/analytics.js我使用//www.google-analytics.com/analytics.js唯一不同的代码,但一切工作正常。在开始时包含https:是否重要?使用一种形式或另一种形式会有什么区别?谢谢。

+1

使用'src =“// example.com”'指示浏览器匹配协议,它被称为“协议相对url”。另请参阅https://*.com/questions/28446314/ – pawel

+1

而在这种特殊情况下_的差异将是,如果您的网站不通过https服务,浏览器需要遵循重定向(因为谷歌重定向到https版本)。 – pawel

这是一个“协议相对网址”。你可以read about them here,但你应该真的只是在这个时候使用https。

下面是链接的资源良好的摘录:

现在SSL鼓励大家,并没有表现 的担忧,现在这种技术是一种反模式。如果您需要的资产 在SSL上可用,则始终使用https://资产。

允许片段通过HTTP请求打开攻击的大门 就像最近的Github Man-on-side攻击一样。即使您的网站使用HTTP, 也会安全地请求HTTPS资产,但是反向 不正确。