![]() ![]() …when measuring the performance of hundreds of thousands of mobile page views, that loading images using a data URI is on average 6x slower than using a binary source link such as an img tag with an src attribute! Some relevant research by Peter McLachlan: may obsolete the coolness of all this, when it gets more supported and people build cool tools for it.Data URIs are not limited to images, they could literally be anything.Setting long expires on CSS files should help. Having a CSS file that is 300k instead of 50k is fine if it saves 6 HTTP requests, but only if that CSS file is cached just as well as those images would be. You should only use this in documents that are heavily cached, like your CSS should be.If you are using PHP (or PHP as CSS), you could create data URIs on the fly like this:.It’s easier to just update an image and replace it. It’s hard to maintain site with embedded data URIs for everything.(HEY?!?! There is that crazy number again.) IE8 has the lowest maximum data URI size of 32768 Bytes.Size of embedded code is somewhat larger than size of resource by itself.Read this article about an alternate technique that does work.Use it only for progressive enhancement type stuff where having no image is perfectly acceptable, or,.Use an IE-only stylesheet to put images in, or,.Browser Compatibilityĭata URI’s don’t work in IE 5-7, but are supported in IE 8. ASCII is another, where the code is essentially URL encoded, or UTF-8. Here’s another drag and drop one.Īlso note that base64 isn’t the only possible format for a data URI and sometimes it isn’t even a good idea. Other than pure document size, this is the #1 factor concerning how fast a page loads. The biggest reason: it saves HTTP Requests. ![]() I’ll be covering the important parts next. You can see a really dumb demo page here. This data is interpreted as the type of file you are saying it is. It’s not gibberish to the browser though of course. The format, to be specific: data:,īasically, a super long string of gibberish characters. Url(data:image/gif base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7) (It’s equally correct to say “Data URL”, which I think I prefer.) Did you know that you don’t have to link to an external image file when using an element in HTML, or declaring a background-image in CSS? You can embed the image data directly into the document with data URIs. ![]()
0 Comments
Leave a Reply. |