Data URL

1Data URLs, URLs prefixed with the data: scheme, allow content creators to embed small files inline in documents. They were formerly known as "data URIs" until that name was retired by the WHATWG.

Data URLs are composed of four parts: a prefix (data:), a MIME type indicating the type of data, an optional base64 token if non-textual, and the data itself:

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

The mediatype is a MIME type string, such as 'image/jpeg' for a JPEG image file. If omitted, defaults to text/plain;charset=US-ASCII

If the data contains characters defined in RFC 3986 as reserved characters, or contains space characters, newline characters, or other non-printing characters, those characters must be URL encoded.

If the data is textual, you can embed the text (using the appropriate entities or escapes based on the enclosing document's type). Otherwise, you can specify base64 to embed base64-encoded binary data. You can find more info on MIME types here and here.

Example 1:

data:,Hello%2C%20World%21

The text/plain data Hello, World!. Note how the comma is URl encoded as %2C, and the space character as %20.

Example 2:

data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==

base64-encoded version of the above

Example 3:

data:text/html,%3Ch1%3EHello%2C%20World%21%3C%2Fh1%3E

An HTML document with <h1>Hello, World!</h1>

Example 4:

data:text/html,%3Cscript%3Ealert%28%27hi%27%29%3B%3C%2Fscript%3E

An HTML document with <script>alert('hi');</script> that executes a JavaScript alert. Note that the closing script tag is required.

Sources:
[1] developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs


Choose from 111 ops
Latest ops 0
Favorite ops 0
Calculations
0