为什么要使用相对协议的 URL? [英] Why use protocol-relative URLs at all?

查看:33
本文介绍了为什么要使用相对协议的 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是 StackOverflow 上经常讨论的一个问题,这意味着什么:

It's been an oft-discussed question on StackOverflow what this means:

 <script src="//cdn.example.com/somewhere/something.js"></script>

这样的好处是,如果您通过 HTTPS 访问它,您会自动获得 HTTPS,而不是可怕的此页面上的元素不安全"警告.

This gives the advantage that if you're accessing it over HTTPS, you get HTTPS automatically, instead of that scary "Insecure elements on this page" warning.

但是为什么要使用相对协议的 URL 呢?为什么不总是在 CDN URL 中简单地使用 HTTPS?毕竟,如果您决定通过 HTTPS 加载 HTTP 页面的某些部分,则没有理由抱怨.

But why use protocol-relative URLs at all? Why not simply use HTTPS always in CDN URLs? After all, an HTTP page has no reason to complain if you decide to load some parts of it over HTTPS.

(这更专门针对 CDN;几乎所有 CDN 都具有 HTTPS 功能.然而,您自己的服务器可能不一定具有 HTTPS.)

(This is more specifically for CDNs; almost all CDNs have HTTPS capability. Whereas, your own server may not necessarily have HTTPS.)

推荐答案

截至 2014 年 12 月,Paul爱尔兰关于协议相对 URL 的博客 说:

As of December 2014, Paul Irish's blog on protocol-relative URLs says:

2014.12.17:既然每个人都鼓励使用 SSL 并且没有性能问题,这种技术现在是一种反模式.如果您需要的资产在 SSL 上可用,则始终使用 https:// 资产.

2014.12.17: Now that SSL is encouraged for everyone and doesn’t have performance concerns, this technique is now an anti-pattern. If the asset you need is available on SSL, then always use the https:// asset.

除非您有特定的性能问题(例如 Zakjan 的回答中提到的慢速移动网络),否则您应该使用 https:// 来保护您的用户.

Unless you have specific performance concerns (such as the slow mobile network mentioned in Zakjan's answer) you should use https:// to protect your users.

这篇关于为什么要使用相对协议的 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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