Web Developers are following lot of techniques to speed up web page performance. Images are part of any modern webpage which gives good appearance at the cost of page performance.
Following are the few techniques that many uses now a days …
- Using sprites + css to avoid many images/http calls to single image/sing http call (SpriteME tool helps you to create sprites for you)
- Using efficent image formats instead of jpg, bmp. gif, png are lighter formats
- Storing images in cdn servers
- Avoid duplicate images across site pages and few more …
Base64 images using Data URL Scheme is another technique to reduce extra http calls to server.
Advantages
- Provides a way to include data in-line in web page itself
- It can be used with js, css & image files
- It saves extra http calls to server.
Ex: if a web page needs 2 js fiels, 2 css files and 5 images then its like 9 http calls to server along with 1 call for web page itself i.e. total 10 calls.
With Data URL format/Base64 you can just have 1 http call that is meant for web page which intern has all js, css and image information.
Take your best decision about using this as some image formats will take more size when representing in Base64 format. I tested with gif of 2KB changed to 3kb of Base64 string and 12kb of png file changed to 3kb of Base64 string. So it is important to use the right image format before applying Base64 logic as it saves extra http call but it will increase the network data size if we don’t use proper image format.
References:
- http://www.greywyvern.com/code/php/binary2base64
- http://en.wikipedia.org/wiki/Data_URI_scheme
- http://stackoverflow.com/questions/4881186/convert-image-to-base64-and-check-size – for C# code
- base64_encode, base64_decode functions in PHP