Zum Inhalt springen

Data-URL

aus Wikipedia, der freien Enzyklopädie
Dies ist eine alte Version dieser Seite, zuletzt bearbeitet am 12. Februar 2005 um 17:14 Uhr durch Minghong (Diskussion | Beiträge). Sie kann sich erheblich von der aktuellen Version unterscheiden.

Vorlage:Wrongtitle

data: URL is a kind of URL that allows inclusion of small data items as "immediate" data, as if it had been included externally. The URLs allow content creators to embed small files inline HTML documents, without complicated, document level formating, like using MIME and cid: or mid:. It is an IETF standard. [1]

It is currently only supported by Mozilla and Opera.

Format

data:[<mediatype>][;base64],

The <mediatype> is an internet media type specification (with optional parameters.) 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 octets 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 "data" URL scheme has no relative URL forms.

Example

An XHTML fragment embedding a small image (newlines are added for better illustration):

<img
src="data:image/gif;base64,R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAw
AAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapyuvUUlvONmOZtfzgFz
ByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSp
a/TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJl
ZeGl9i2icVqaNVailT6F5iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uis
F81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97Vriy/Xl4/f1cf5VWzXyym7PH
hhx4dbgYKAAA7"
alt="Larry" />

Note that as an URL, the data: URL should be formattable with whitespaces, but there are practical issues with how that relates to base64 encoding [2]. Authors should ignore using whitespaces for base64 encoded data: URLs.

Limitations

While URL should be essentially unlimited in length, some user agents (web browsers) do not support unlimited length URLs. For example, URLs in Opera are limited to around 4100 characters. Authors should restrict the use of data: URLs to small media files only.

See also