为什么要使用数据URI方案? [英] Why use data URI scheme?

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

问题描述

基本上,问题是在标题。

Basically the question is in the title.

很多人都有过的如何创建一个数据问题计算器URI和其中的问题。

Many people have had the question stackoverflow of how to create a data URI and problems therein.

我的问题是的为何使用数据URI?

有哪些优势来这样做的:

What are the advantages to doing:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />

在这样做的:

<img src="dot.png" alt="Red dot" />

我明白了一对服务器端(也许)较少的开销,但什么是在真正 /缺点优点使用的数据URI 的?

I understand one has less overhead on the server side (maybe), but what are the real advantages/disadvantages to using data URI?

推荐答案

根据维基百科

优点:


  • HTTP不需要嵌入数据请求和首部的流量,从而
    数据URI消耗更少的带宽,每当编码的开销
    内联内容作为数据URI比HTTP开销较小。
    例如,所需的base64编码为图像600字节长
    将是800个字节,因此,如果一个HTTP请求需要200多
    开销字节,数据URI会更有效率。

  • HTTP request and header traffic is not required for embedded data, so data URIs consume less bandwidth whenever the overhead of encoding the inline content as a data URI is smaller than the HTTP overhead. For example, the required base64 encoding for an image 600 bytes long would be 800 bytes, so if an HTTP request required more than 200 bytes of overhead, the data URI would be more efficient.

有关传输许多小文件(小于每一个几千字节),这可能会更快。 TCP传输通常启动缓慢。如果每个文件都需要一个新的TCP连接,传送速度是由往返时间,而不是可用带宽的限制。使用HTTP保持活动改善的情况,但可能无法完全缓解瓶颈。

For transferring many small files (less than a few kilobytes each), this can be faster. TCP transfers tend to start slowly. If each file requires a new TCP connection, the transfer speed is limited by the round-trip time rather than the available bandwidth. Using HTTP keep-alive improves the situation, but may not entirely alleviate the bottleneck.

当浏览一个安全的HTTPS的网站,网页浏览器通常需要一个网页的所有元素通过安全连接被下载,或用户将被通知减少安全的由于安全和不安全元素的混合物。在配置不当的服务器上,HTTPS请求有超过普通的HTTP请求显著开销,因此在嵌入数据URI数据可能会改善这种情况下的速度。

When browsing a secure HTTPS web site, web browsers commonly require that all elements of a web page be downloaded over secure connections, or the user will be notified of reduced security due to a mixture of secure and insecure elements. On badly configured servers, HTTPS requests have significant overhead over common HTTP requests, so embedding data in data URIs may improve speed in this case.

Web浏览器通常被配置为只作一定数量
(常二)并发的HTTP连接到域,所以内联
数据释放了其他内容的下载连接。

Web browsers are usually configured to make only a certain number (often two) of concurrent HTTP connections to a domain, so inline data frees up a download connection for other content.

有限或限制访问外部资源环境
可以嵌入内容时它是不允许的或不切实际的参考
它在外部。例如,一个先进的HTML编辑字段可能
接受粘贴或插入的图像并将其转换成数据URI来
隐藏外部资源的来自用户的复杂性。
另外,浏览器可以转换(EN code)从基于图像数据
剪贴板数据URI并将其粘贴在HTML编辑字段。
Mozilla Firefox浏览器4支持此功能。

Environments with limited or restricted access to external resources may embed content when it is disallowed or impractical to reference it externally. For example, an advanced HTML editing field could accept a pasted or inserted image and convert it to a data URI to hide the complexity of external resources from the user. Alternatively, a browser can convert (encode) image based data from the clipboard to a data URI and paste it in a HTML editing field. Mozilla Firefox 4 supports this functionality.

有可能管理一个多媒体页面作为单个文件。电子邮件
消息模板可以包含图像(背景或签名)
没有出现被扣押的形象。

It is possible to manage a multimedia page as a single file. Email message templates can contain images (for backgrounds or signatures) without the image appearing to be an "attachment".

缺点:


  • 数据URI不单独从其含有的文件缓存
    (例如CSS或HTML文件),所以数据被下载每次
    含文档重新下载。内容必须重新连接$ C $的CD和
    重新嵌入每一次变更时。

  • Data URIs are not separately cached from their containing documents (e.g. CSS or HTML files) so data is downloaded every time the containing documents are redownloaded. Content must be re-encoded and re-embedded every time a change is made.

的Internet Explorer至7版本(市场约15%,为2011年1月),缺乏支持。然而,这可以通过浏览器提供服务的具体内容加以克服。
Internet Explorer 8的极限数据URI为32 KB的最大长度。

Internet Explorer through version 7 (approximately 15% of the market as of January 2011), lacks support. However this can be overcome by serving browser specific content. Internet Explorer 8 limits data URIs to a maximum length of 32 KB.

数据是作为一个简单的数据流,并使用容器(如多重/替代或消息/ RFC822),以提供更大的复杂性,如元数据,数据多处理环境(如Web浏览器),可能不支持COM pression或内容协商。

Data is included as a simple stream, and many processing environments (such as web browsers) may not support using containers (such as multipart/alternative or message/rfc822) to provide greater complexity such as metadata, data compression, or content negotiation.

Base64的恩codeD数据URI的大小比二进制大1/3
当量。 (但是,此开销如果HTTP减少到2-3%
服务器COM presses使用gzip)数据URI使其更响应
困难的安全软件来过滤内容。

Base64-encoded data URIs are 1/3 larger in size than their binary equivalent. (However, this overhead is reduced to 2-3% if the HTTP server compresses the response using gzip) Data URIs make it more difficult for security software to filter content.

根据其他来源
  - 数据网址是在移动浏览器显著慢

According to other sources - Data URLs are significantly slower on mobile browsers.

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

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