Data URI scheme: Difference between revisions

Content deleted Content added
reflect change of name (hope no-one minds); mention IE's old "about:" behaviour
Line 1:
{{lowercase|title=data: URLURI scheme}}
 
The '''data: URLURI scheme'''s, as defined by [[IETF]] standard (RFC 2397), areis a kind of [[UniformURI Resource Locator|URLscheme]] (even though they do not ''locate'' a resource) that allows inclusion of small data items inline, as if they hadwere beenbeing includedreferenced externallyin an external resource. They tend to be far simpler than alternative inclusion methods, such as [[MIME]] with <tt>cid:</tt> or <tt>mid:</tt>. According to the wording in the RFC, <tt>data:</tt> URIs are in fact URLs ([[Uniform Resource Locator]]s), although they do not actually locate anything.
 
ItThe scheme is currently supported by [[Mozilla Application Suite|Mozilla]] (and its derivatives, likesuch as [[Mozilla Firefox|Firefox]]), [[Opera (web browser)|Opera]], [[Safari (web browser)|Safari]] and [[Konqueror]]. [[Microsoft]]'s [[Internet Explorer]], as of version 6, does not support <tt>data:</tt> URLsURIs. Early versions of [[Internet Explorer]] treated unrecognised <tt>[[about: URI scheme|about:]]</tt> URIs as HTML source, so something like <code><nowiki>about:<b>bold</b></nowiki></code> in these versions was broadly equivalent to <code><nowiki>data:text/html,<b>bold</b></nowiki></code> in browsers that support <tt>data:</tt> URIs
 
===Advantages===
 
* [[HyperText Transfer Protocol|HTTP]] headers are not required for embedded data, so <tt>data:</tt> URLsURIs can use fewer network resources when the overhead of encoding the inline content as a <tt>data:</tt> URLURI is smaller than the HTTP headers that would otherwise be required.
* Web browsers are typically limited to four concurrent connections to a server, so inline data frees up a download connection for other content.
* Browsers manage fewer cache entries for a file that contains <tt>data:</tt> URLsURIs.
* Environments with limited or restricted access to external resources may embed content when it is disallowed or impractical to reference externally. For example, an advanced HTML editing field could accept a pasted or inserted image and convert it to a <tt>data:</tt> URLURI to hide the complexity of external resources from the user.
 
===Disadvantages===
 
* Embedded content must be extracted and decoded before changes may be made, then re-encoded and re-embedded afterward.
* Base64-encoded <tt>data:</tt> URLsURIs are roughly 50% larger in size than their binary equivalent.
* URL-encoded <tt>data:</tt> URLsURIs can be up to three times larger (in extreme cases) than the original text content.
* Information that is embedded more than once is redownloaded as part of the containing file, and does not benefit from the browser's cache.
* Browser limits to URLURI length provide a maximum data size. For example, URLsURIs in Opera are limited to around 4100 characters.
 
==Format==
data:[<mediatype>][;base64],<data>
 
The <mediatype> is an internet media type specification (with optional parameters.; see [[MIME]]). The appearance of ";base64" means that the data is encoded as [[base64]]. Without ";base64", the data (as a sequence of octets) is represented using [[ASCII]] encoding for [[octet]]s inside the range of safe URL characters and using the standard %xx hex encoding of URLs for octets outside that range. If <mediatype> is omitted, it defaults to text/plain;charset=US-ASCII. As a shorthand, "text/plain" can be omitted but the charset parameter supplied.
 
The "<tt>data":</tt> URLURI scheme has no relative URL forms.
 
==Examples==
Line 46:
[[Image:DataUrlLarry.gif]]
 
Note that as ana URLURI, the data: URLURI should be formattable with [[whitespace]]s, but there are practical issues with how that relates to base64 encoding [http://bugzilla.mozilla.org/show_bug.cgi?id=73026#c12]. Authors should ignore using whitespaces for base64 encoded data: URLsURIs.
 
===CSS===
Line 66:
'd%3E%0D%0A%3Cbody%3E%3Ch1%3E42%3C%2Fh1%3E%3C%2Fbody%3E%0D%0A%3C%2Fhtml%3E'+
'%0D%0A','_blank','height=300,width=400');
 
==See also==
*[[URL]]
 
==External links==