Base 64 Encode Vs Loading An Image File
Solution 1:
- Base64 encoding makes the file bigger and therefore slower to transfer.
- By including the image in the page, it has to be downloaded every time. External images are normally only downloaded once and then cached by the browser.
- It isn't compatible with all browsers
Solution 2:
Well I don't agree with anyone of you. There are cases when you've to load more and more images. Not all the pages contain 3 images at all. Actually I'm working on a site where you've to load more than 200 images. What happens when 100000 users request that 200 images on a very loaded site. The disks of the server, returning the images should collapse. Even worse you've to make so much request to the server instead of one with base64. For so much thumbnails I'd prefer the base64 representation, pre-saved in the database. I found the solution and a strong argumentation at http://www.stoimen.com/2009/04/23/when-you-should-use-base64-for-images/. The guy is really in that case and made some tests. I was impressed and make my tests as well. The reality is like it says. For so much images loaded in one page the one response from the server is really helpful.
Solution 3:
Why regenerate the image again and again if it will not be modified. Hypothetically, even if there are a 1000 different possible images to be shown based on 1000 different conditions, I still think that 1000 images on the disks are better. Remember, disk based images can be cached by the browser and save bandwidth etc etc.
Solution 4:
To answer the initial question, I ran a test measuring a jpeg image 400x300 px in 96 ppi:
base64ImageData.Length
177732
bitmap.Length
129882
Solution 5:
I have used base64 images once or twice for icons (10x10 pixels or so).
Base64 images pros:
- compact - you have single file. also if file is compressed, base64 image is compressed almost to the size of normal image.
- page is retrieved in single request.
Base64 images cons:
- to be realistic, you probably need to use scripting engine (such PHP) on all pages that contains the image.
- if image is changed, all cached pages must be re-downloaded.
- because image is inline, you can not use CDN or static content web server.
Normal images pros:
- if you are use SPDY protocol, at least theoretical, page + images + CSS will load with single request too.
- you can set expiration on the image, so content will be cached from the browsers.
Post a Comment for "Base 64 Encode Vs Loading An Image File"