Community Documentation

Data URIs

Last updated February 20, 2012. Created by jbrown on January 14, 2012.
Log in to edit this page.

Instead of linking to a file, Data URIs contain the file itself. This means that images can be embedded directly into HTML documents.

For pages with small images (thumbnails) this is can really increase front-end performance. There is a per-file overhead, so downloading lots of small files (even on a fast connection) can be slow.

The downside is that they are cached with the page. If the same image is to appear on another page, it will have to be embedded into the document again. It does not make sense for large images to be embedded as data URIs.

Also, they should not be used for files greater than 32kB anyway as IE8 will not support them.

IE6 and 7 do not support data URIs. All other browsers have good support.

Storage API 7.x-1.1 will be able to output data URIs, but it requires Drupal core to support them. It does not yet, but you can apply the D7 patch from #1342504: Support data URIs.

It may be necessary to delete the variable filter_allowed_protocols after applying the patch.

Containers serving data URIs should be local so that they can be read quickly by Drupal. A class should be created have the data URI option enabled. This can then be specified in image styles as the class for thumbnails.

It doesn't make sense for an image field's default image to be served as a data URI as it may appear multiple times on a page and may also appear on more pages. A separate class can therefore be specified for the default images for each style.

Page status

About this page

Drupal version
Drupal 7.x
Audience
Programmers, Site administrators
Level
Intermediate

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here