Mobile app version of vmapp.org
Login or Join
Vandalay111

: Advantages and disadvantages of base64 image strings I discovered that you can covert images into base64 strings and use those string within img tags and css like this: <img alt="" src="data:image/png;base64,iVBORw0KGgoAhEU

@Vandalay111

Posted in: #Browsers #Cache #ContentEncoding #Images

I discovered that you can covert images into base64 strings and use those string within img tags and css like this:

<img alt="" src="data:image/png;base64,iVBORw0KGgoAhEUgAAA ... FTkSuQmCC" />


or this:

background-image: url(data:image/png;base64,iVBORw0KGgoAAAA ... uQmCC);


Serving images in this way seems improve website load times, but may have some drawbacks. I have a few questions about this method:


Will the browser cache these images?
Is it faster for a page to render this string or an image file?


I am interested in other advantages or disadvantages involving this image serving method.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Vandalay111

1 Comments

Sorted by latest first Latest Oldest Best

 

@Rambettina238

Will the browser cache these images?


Well, what do you mean by caching in this context? Browsers cache static files so they don't have to request them again. If the image data is provided inline in the HTML page itself, no caching is required.

If the image data is supplied in the stylesheet, then since the stylesheet itself will be cached, the image data is cached with it.


Is it faster for a page to render this string or an image file?


I would guess that the difference there is negligible and not worth considering.

Also, answering a question from your comment, I'd generally only consider inlining image data in the HTML source in situations where there are very small images that are only used on that one page.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme