我可以将所有http://链接更改为//吗? [英] Can I change all my http:// links to just //?

查看:134
本文介绍了我可以将所有http://链接更改为//吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dave Ward 说,


这不是简单的阅读,但 RFC 3986的第4.2节提供了完全限定协议(HTTP或HTTPS)的完全限定URL。当省略URL的协议时,浏览器会使用基础文档的协议。

It’s not exactly light reading, but section 4.2 of RFC 3986 provides for fully qualified URLs that omit protocol (the HTTP or HTTPS) altogether. When a URL’s protocol is omitted, the browser uses the underlying document’s protocol instead.

简而言之,这些无协议URL允许这样的引用在每个浏览器你会试试:

Put simply, these "protocol-less" URLs allow a reference like this to work in every browser you’ll try it in:

// ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min .js

起初看起来很奇怪,但这种无协议的URL是引用第三方内容的最佳方式HTTP和HTTPS。

It looks strange at first, but this "protocol-less" URL is the best way to reference third party content that’s available via both HTTP and HTTPS.

这肯定会解决我们在HTTP页面上看到的一堆混合内容错误 - 假设我们的资产可以通过HTTP和HTTPS获得。

This would certainly solve a bunch of mixed-content errors we're seeing on HTTP pages -- assuming that our assets are available via both HTTP and HTTPS.

这是完全跨浏览器兼容吗?还有其他警告吗?

Is this completely cross-browser compatible? Are there any other caveats?

推荐答案

我在发布之前对其进行了彻底的测试。在 Browsershots 中可用于测试的所有浏览器中,我只能找到一个未正确处理协议相对URL的浏览器:一个名不见经传的* nix浏览器,名为 Dillo

I tested it thoroughly before publishing. Of all the browsers available to test against on Browsershots, I could only find one that did not handle the protocol relative URL correctly: an obscure *nix browser called Dillo.

有两个缺点,我收到的反馈是:

There are two drawbacks I've received feedback about:


  1. 当你打开一个本地文件时,无协议的URL可能无法正常工作您的浏览器,因为页面的基本协议将是file:///。特别是当您使用无协议URL作为外部资源(如CDN托管资产)时。使用Apache或IIS等本地Web服务器测试 http:// localhost 地址可以正常工作。

  2. 显然,至少有一个iPhone提要阅读器应用程序无法正确处理无协议URL。我不知道哪个有问题或有多受欢迎。对于托管JavaScript文件,这不是一个大问题,因为RSS阅读器通常无论如何都会忽略JavaScript内容。但是,如果您将这些URL用于需要通过RSS进行联合的内容中的图像(例如,单个平台上的这个单一阅读器应用程序可能占读者数量非常少),则可能会出现问题。 / li>
  1. Protocol-less URLs may not work as expected when you "open" a local file in your browser, because the page's base protocol will be file:///. Especially when you're using the protocol-less URL for an external resource like a CDN-hosted asset. Using a local web server like Apache or IIS to test against http://localhost addresses works fine though.
  2. Apparently there's at least one iPhone feed reader app that does not handle the protocol-less URLs correctly. I'm not aware of which one has the problem or how popular it is. For hosting a JavaScript file, that's not a big problem since RSS readers typically ignore JavaScript content anyway. However, it could be an issue if you're using these URLs for media like images inside content that needs to be syndicated via RSS (though, this single reader app on a single platform probably accounts for a very marginal number of readers).

这篇关于我可以将所有http://链接更改为//吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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