通过使用图像源的协议相对 URL 来防止安全/不安全错误
有谁知道使用 图像源的协议相对 URL,以防止混合内容安全警告。
例如,链接像这样的图像:
<img src="//domain.com/img.jpg" />
而不是:
<img src="http://domain.com/img.jpg" />
or
<img src="https//domain.com/img.jpg" />
在我的测试中,我没有看到任何表明这是错误的,但我不确定它是否存在会产生问题的边缘情况。
编辑我发现它在使用PHP的getimagesize 函数。
Is anyone aware of whether it is problematic to use protocol relative URLs for an image source to prevent mixed content security warnings.
For example linking an image like:
<img src="//domain.com/img.jpg" />
instead of:
<img src="http://domain.com/img.jpg" />
or
<img src="https//domain.com/img.jpg" />
In my testing i've not seen anything to suggest this is wrong but i'm not sure if it has edge cases where it will create problems.
EDIT i've seen it throw errors when using PHP's getimagesize function.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
发现了使用协议相对 URL 的一个有趣的问题:
来自此处
本质上,虽然没有充分的理由说明为什么这不应该起作用,只要该请求是由浏览器而不是外部电子邮件客户端发出的。
更多信息来自此处:
Found an interesting gotcha for the use of protocol relative URLs:
from here
Essentially though there are no valid reasons why this shouldn't work as long as the request is made by a browser and not an external email client.
more info from here:
IE 7 和 IE 8 将下载样式表两次< /a> 如果您使用的是协议相关 URL。如果您仅将其用于“图像源”,这不会影响您,但以防万一。
IE 7 and IE 8 will download stylesheets twice if you're using a protocol-relative URL. That won't affect you if you only use it "for an image source", but just in case.
使用协议相关 URL 时应考虑以下事项:
1) 所有现代浏览器都支持此功能。
2) 我们必须确保请求的资源可以通过 HTTP 和 HTTPS 访问。如果 HTTP 重定向到 HTTPS 没问题,但这里的加载时间会比直接向 HTTPS 发出请求要长一些。
3) Internet Explorer 6不支持此功能。
4) Internet Explorer 7 和 8 支持该功能,但如果 css 文件使用协议相关 URL,它们将下载样式表两次。
The following should be considered when using Protocol-Relative URLs:
1) All modern browsers support this feature.
2) We have to be sure that the requested resource is accessible over both HTTP and HTTPS. If HTTP redirects to HTTPS it is fine, but here the load time will take a little longer than if the request was made directly to the HTTPS.
3) Internet Explorer 6 does not support this feature.
4) Internet Explorer 7 and 8 support the feature, but they will download a stylesheet twice if protocol-relative URLs are used for the css files.