Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are drawbacks of using data URI instead of sprite images?

Consider this conditions for my website:

  • I don't support IE8 and below so browser support is not a problem.

  • I also use gzip that would avoid data overload in CSS in cases that I copy and paste data URI images in my CSS file.

  • I only have one CSS file that is generated by LESS.

  • To make it easy, I use LESS variable for each image data URI.

  • I put images variables in a separated LESS file to keep my codebase clean

With all this I am still not sure if it's best approach for loading images. Loading small images with this approach reduces number of HTTP requests and also we don't have to maintain a sprite image.

Is there any drawback in this approach you can think of?

like image 777
Mohsen Avatar asked Nov 17 '12 01:11

Mohsen


People also ask

What is the use of data URI?

What Is a Data URI? A data URI is a base64 encoded string that represents a file. Getting the contents of a file as a string means that you can directly embed the data within your HTML or CSS code. When the browser encounters a data URI in your code, it's able to decode the data and construct the original file.

What is data URI image?

A Data URL is a URI scheme that provides a way to inline data in an HTML document. Say you want to embed a small image. You could go the usual way, upload it to a folder and use the img tag to make the browser reference it from the network: <img src="image.png" />


1 Answers

If any image changes, the entire css file has to change. This breaks HTTP cache. With a sprite image, the css file itself would be served from cache, and only the changed image would have to be downloaded again.

It may be better to generate a css file only for the data:URI images, and another for the regular CSS stuff. This way, regular css updates don't require re-downloading the data:uri images.

Second problem is with foreground images, those that are served with <img> tag in the html. If it is a frequently used image, it will unnecessarily increase the size of the html.

like image 108
Sripathi Krishnan Avatar answered Sep 22 '22 20:09

Sripathi Krishnan