댓글 0건 조회 2,183회 작성일 11-04-02 11:37
The data URI scheme is a URI scheme that provides a way to include data in-line in web pages as if they were external resources. It tends to be simpler than other inclusion methods, such asMIME with cid or mid URIs. Data URIs are sometimes called Uniform Resource Locators, although they do not actually locate anything remote. The data URI scheme is defined in RFC 2397 of theInternet Engineering Task Force (IETF).
The IETF published the data URI specification in 1998 as Proposed Standard on the IETF Standards Track, and hasn't progressed it since. The HTML 4.01 specification refers to the data URI scheme, and data URIs have now been implemented in most browsers.
Web browser support
Data URIs are currently supported by the following web browsers:
- Gecko-based, such as Firefox, SeaMonkey, XeroBank, Camino, Fennec and K-Meleon
- Konqueror, via KDE's KIO slaves input/output system
- Opera (including devices such as the Nintendo DSi or Wii)
- WebKit-based, such as Safari (including on iOS), Android's browser, Epiphany and Midori (WebKit is a derivative of Konqueror's KHTML engine, but Mac OS X does not share the KIO architecture so the implementations are different), and Webkit/Chromium-based, such as Chrome
- CSS declarations that accept a URL, such as
- Internet Explorer 9: Internet Explorer 9 does not have 32KiB limitation and allowed in broader elements.
- 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.
- 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.
- 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. HTTPS requests have significant overhead over common HTTP requests, so embedding data in data URIs may improve speed in this case.
- 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.
- 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".
- 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 through version 7 (approximately 15% of the market as of January 2011), lacks support.
- Internet Explorer 8 limits data URIs to a maximum length of 32 KB.
- Data is included as a simple stream, and many processing environments (such as web browsers) may not support using containers (such as
message/rfc822) to provide greater complexity such as metadata, data compression, or content negotiation.
- 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 usinggzip)
- Data URIs make it more difficult for security software to filter content.
The encoding is indicated by
;base64. If it's present the data is encoded as base64. Without it the data (as a sequence of octets) is represented using ASCII encoding for octets inside the range of safe URL characters and using the standard %xx hex encoding of URLs for octets outside that range. If
<MIME-type> is omitted, it defaults to
text/plain;charset=US-ASCII. (As a shorthand, the type can be omitted but the charset parameter supplied.)
Some[which?] browsers accept a non-standard ordering if both
;charset are supplied. Google Chrome works correctly only if
;base64 appears before
data:text/html;base64;charset=utf-8,data, which is in violation of the standard.
An HTML fragment embedding a picture of small red dot:
As demonstrated above, data URIs may contain whitespace for readability.
A CSS rule that includes a background image:
This example does not work with Internet Explorer 8 due to its security restrictions that prevent navigable file types from being used.
등록된 댓글이 없습니다.