为什么没有为这个Facebook脚本标签指定协议 [英] why is there no protocol specified for this facebook script tag

查看:111
本文介绍了为什么没有为这个Facebook脚本标签指定协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这样我可以生成一个类似的按钮:D

With this I can generate a like button :D

<script>(function(d, s, id) {

  var js, fjs = d.getElementsByTagName(s)[0];

  if (d.getElementById(id)) return;

  js = d.createElement(s); js.id = id;

  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";

  fjs.parentNode.insertBefore(js, fjs);

}(document, 'script', 'facebook-jssdk'));</script>

但为什么不是

.src =某些协议 // connect.facebook.net/en_US/all.js#xfbml=1;

js.src = "some protocol://connect.facebook.net/en_US/all.js#xfbml=1";

为什么不具体的协议?

推荐答案

这是一个有用的技巧,它允许您使用在HTTP和HTTPS页面上工作的单个引用。当URL的协议被省略时,浏览器将使用底层文档的协议。

That’s a helpful trick which allows you to use a single reference that works on both HTTP and HTTPS pages. When a URL’s protocol is omitted, the browser uses the underlying document’s protocol instead.

在通过常规,未加密的HTTP加载的页面上,使用该URL的脚本引用将通过HTTP并被正常缓存。同样,在通过HTTPS加载的安全页面上。

On a page loaded through regular, unencrypted HTTP, script references using that URL will be loaded via HTTP and be cached as normal. Likewise, on a secure page that was loaded via HTTPS.

因此,使用无协议的URL允许单个脚本引用适应自己最优化的方式:HTTP和它在HTTP页面上完全缓存支持,在安全页面上使用HTTPS,以便您的用户不会面临混合内容警告。

Thus, using the protocol-less URL allows a single script reference to adapt itself to what’s most optimal: HTTP and it’s full caching support on HTTP pages, and HTTPS on secured pages so that your users aren’t confronted with a mixed content warning.

来源: http://encosia.com/cripple-the-google-cdns-caching-with-a-single -character /

这篇关于为什么没有为这个Facebook脚本标签指定协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆