Any front end developer worth their salt will know that it’s important to reduce load time on a website. One way is to reduce the number of http requests the page has. Sounds simple right? Well guess what…it is! You can reduce http requests with data URI’s in no time at all.
Data URI’s have been around since 1998, and it’s a bit of a mystery why they are not widely used, especially on large sites. You are basically embedding the http requests into the site rather than loading the markup, then grabbing each image, video or whatever else one at a time. So it’s a good idea to get into the habit of implementing them into your projects in the early stages of development, and here’s a quick tut on how to do so.
You may have an image that you want to display, so you’d use your trusty <img> tag like so:
<img src="http://www.moosch.co.uk/wp-content/uploads/2012/07/paw.gif" alt="paw print" title="paw print" />
And you’d get the image once the page is loaded.
Fantastic huh? But what about using these Data URI’s? Well it’s super simple. Your <img> tag will look like this:
Now that looks crazy doesn’t it, but don’t worry it’s really not. All I did to get this was use a Data URI converter I found online. There are quite a few out there to use but they all mostly do the same thing. Chris Coyier from CSS-Tricks recommends websemantics.co.uk which is nice as it gives you the code for css, html and raw data, but you must upload the image. So if you’re updating an existing site, and you just want to use the image locations I suggest the simplicity of dopiaza.
So there you have it. Nice and easy right? Well not quite. If you are concerned about IE support, which as a front end developer you should be, you’ll find this doesn’t work in IE5-7, but it does work in IE8+. So you have a few options, either ignore it and don’t support anything less than IE8, use progressive enhancement to only show text for IE5-7 and ignore images. If you are implementing data scheme in your css, you can easily support the old IE’s by simply using IE Only stylesheets.
But if you really must support the older IE’s this post by Stoyan Stefanov will teach you all you need to know. As for me I don’t bother supporting IE5-7 as Microsoft has dropped support for them, and if the creators have lost interest, we all probably should.