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

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

问题描述

这样我可以生成一个赞按钮: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>

但是为什么不

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

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

为什么没有特定的协议?

Why no specific the protocol?

推荐答案

这是一个有用的技巧,可让您使用在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/

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

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