Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to consider base64 (DATA: URI) images?

Tags:

css

image

base64

What are the factors that should trigger thinking about switching images over to Base64 embedded in CSS?

There seems to be a lot of generic pro/con type things out there. Wikipedia seems to have a decent overview: http://en.wikipedia.org/wiki/Data_URI_scheme#Advantages

From what I've read, the one factor that seems to make base64 an easy decision would be if your site has to access a lot of individual small images and having one large file would be more efficient that hitting the server 50 times for each individual image.

But...it also seems that with sprites and the fact that rarely would I need 50 separate images on a page, Base64 isn't offering a whole lot for general web sites.

Are there are key factors I should be looking for (both pro/con)?

(This may better as a community wiki entry rather than question)

UPDATE:

Perhaps a more succinct way to word the question:

Given these two options:

1) All images converted to base64 and embedded in the external css file

2) Images gathered into a handful of sprite images, referenced in the external css file

Are there obvious situations where one is better than the other, or is it really just a case-by-case, do both and test type of thing?

like image 262
DA. Avatar asked Apr 13 '11 14:04

DA.


People also ask

What is Base64 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.

Should I use Base64 images?

The issues are actually not only limited to performance. By using Base64 encoded images on your website, you might also be hurting both your SEO and user experience as well. The reason for this is that sharing Base64 images is much harder due to the fact that they are not actually accessible via a public URL.

What is data URI of image?

Introduction. 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" />

Can Base64 be used in URL?

Base64 is a group of binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. By consisting only of ASCII characters, base64 strings are generally url-safe, and that's why they can be used to encode data in Data URLs.


1 Answers

Are there are key factors I should be looking for (both pro/con)?

The biggest con is the missing support in IE6/7, and the incomplete support in IE8 (data: URIs must not be larger than 32 kilobytes there).

Using CSS sprites is the vastly superior technique in this case.

like image 160
Pekka Avatar answered Nov 15 '22 09:11

Pekka