Reputation: 13521
I creating a WordPress theme, and I have implement a function that allowing the images to be served embeded into the HTML document and the CSS files.
What I mean is that instead of adding images in my web site as:
<!-- In HMTL -->
<img src="http://www.some-url.ext/img/my_image.jpg" />
/* In CSS */
selector
{
background-image: url(http://www.some-url.ext/img/my_image.jpg);
}
to add the image in my site in the following form:
<!-- In HMTL -->
<img src="data:image/gif;base64,R0lG...." />
/* In CSS */
selector
{
background-image: url(data:image/gif;base64,R0lG....);
}
The processed images are stored in cache files for better performance.
My current theme also has a full width slider, that contains images that are large.
The issue is that the processed document has the size of 1.83MB because of the embeded images.
Also the document while is loading very fast, anything bellow the slideshow is getting slower to be displayed :(
So, is it better to embed the images into the document or is it better to use the normal way with URLs ?
Upvotes: 0
Views: 3636
Reputation: 201886
I suppose the implied criterion here is efficiency. For caching reasons, images should normally be served as separate, since then each image can be cached. Otherwise, only the entire document containing image data can be cached, and unless it is a very stable document and the images are used in this document only, it gets rather inefficient.
Check out http://www.mnot.net/cache_docs/ for general info on caching. Normally, any reasonable cache-friendliness server-side (often on by default) will make images well cacheable, as they don’t change often.
Upvotes: 1
Reputation: 12115
The answer, as usual, is "it depends". Here are some points of interest:
See http://en.wikipedia.org/wiki/Data_URI_scheme for a more exhaustive list of pros and cons.
For large images, I would say you're better off taking the HTTP request hit. You can use various preloading schemes to make the HTTP hits less visible to the user.
PageSpeed, YSlow, etc., are guidelines, not gospel. As you are finding, you should always test the changes and find out what makes sense for your site.
Upvotes: 3
Reputation: 14123
In general, using Data URI makes sense for small images only (like multiple icons united into one sprite). Big images should be served as separate files.
Upvotes: 1