<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: When you should use base64 for images</title>
	<atom:link href="http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/</link>
	<description>about web development</description>
	<lastBuildDate>Fri, 03 Feb 2012 22:35:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: AntoxaGray</title>
		<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/comment-page-1/#comment-14920</link>
		<dc:creator>AntoxaGray</dc:creator>
		<pubDate>Tue, 20 Dec 2011 05:33:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.stoimen.com/blog/?p=538#comment-14920</guid>
		<description>How about newsletter? Should I use base64 conversion there? (yes, I know, who reads newsletters anyway).</description>
		<content:encoded><![CDATA[<p>How about newsletter? Should I use base64 conversion there? (yes, I know, who reads newsletters anyway).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: konan75</title>
		<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/comment-page-1/#comment-14720</link>
		<dc:creator>konan75</dc:creator>
		<pubDate>Wed, 30 Nov 2011 15:14:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.stoimen.com/blog/?p=538#comment-14720</guid>
		<description>I prefer to tune my server too. I&#039;ve developed a Lotus Domino portal, accessed by 20.000 persons every day. Users are still using IE6, and I&#039;ve noticed this agent has some problem in managing backgrounds. I&#039;ve lists of links in every page of portal, shown by means of LI tags, and an anchor nested. These anchors have a css class with background setted, to override LI defaults. With empty &quot;temporary internet files&quot; folder (cache), IE6 doesn&#039;t request image file once, but a request for every LI&gt;A in the page. I&#039;ve modified my web server rules to override default expiration; the new expire data is setted, but it doesn&#039;t work in the empty cache scenario. In a section of the portal there are more than 100 of these images and IE6 does more than 100 different requests. I&#039;m using Fiddler proxy to check this out.

Any suggestion to avoid this overhead?
Thanks in advance
K.</description>
		<content:encoded><![CDATA[<p>I prefer to tune my server too. I&#8217;ve developed a Lotus Domino portal, accessed by 20.000 persons every day. Users are still using IE6, and I&#8217;ve noticed this agent has some problem in managing backgrounds. I&#8217;ve lists of links in every page of portal, shown by means of LI tags, and an anchor nested. These anchors have a css class with background setted, to override LI defaults. With empty &#8220;temporary internet files&#8221; folder (cache), IE6 doesn&#8217;t request image file once, but a request for every LI&gt;A in the page. I&#8217;ve modified my web server rules to override default expiration; the new expire data is setted, but it doesn&#8217;t work in the empty cache scenario. In a section of the portal there are more than 100 of these images and IE6 does more than 100 different requests. I&#8217;m using Fiddler proxy to check this out.</p>
<p>Any suggestion to avoid this overhead?<br />
Thanks in advance<br />
K.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: There are those who call me Tim?</title>
		<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/comment-page-1/#comment-13462</link>
		<dc:creator>There are those who call me Tim?</dc:creator>
		<pubDate>Tue, 26 Oct 2010 17:54:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.stoimen.com/blog/?p=538#comment-13462</guid>
		<description>Oh, boy, this use case is just WRONG.

The problem is that people are confusing &quot;request&quot; with &quot;connection&quot;.  You want to avoid CONNECTIONS, multiple REQUESTS over one connection is very cheap, and commonplace.  The one TCP connection per request idiom does not exist in practice thanks to HTTP 1.1.

100 small images == 3 or less connections on my Apache/Linux server. 

HTTP 1.1 has a &quot;Connection: Keep-Alive&quot; header.
This is supported by ALL modern browsers (even mobile) and ALL modern servers (IIS, Tomcat, Apache, etc.)

With Keep-Alive: The browser and server leave the connection open at the &quot;end&quot; of a request.  The browser can send additional HTTP 1.1 requests to the server, and the server sends the requested data back over the same single connection.

With static content this translates to Reading all 100 images from disk, and sending them to the client all in one go.

If one of the 100 images changes ONLY that image will be re-sent, the rest will result in a &quot;No Change&quot; reply.

Don&#039;t dynamically generate data unless you have to, and when you do generate &quot;dynamic&quot; data make sure to set the caching headers so that multiple requests for the same &quot;dynamic&quot; content don&#039;t require a full request / database lookup / transmission.

Base64 encoding should NOT be used to fix a &quot;too many connections&quot; issue, see your server configuration for that.

The &quot;too many requests&quot; issue is a misnomer since all modern servers &amp; browsers allow multiple requests over one connection, and the requests are VERY cheap.  

Base64 encoding multiple images into one CSS file is a benefit only when the image data is smaller than an HTTP Request header (mostly never).  Base64 it&#039;s a 3 to 4 increase of data size, and is only worth using when the base 64 encoded data is smaller than the HTTP Header (very small images &lt; 8x8).

Even this is a silly way do do things.   Lets say I have 100 very small images, I can paste them all into ONE big image, and serve up &quot;palette.png&quot; as a single static image.
To get at the individual images just use CSS.

#my_icon {
  display: inline-block;
  backgroundImage: url(&quot;palette.png&quot;);
  width: 16px; height: 16px;
  backgroundPosition: -48px -160px;
}
#my_icon2{
  /* same as above, with different bkg Pos */
}
------

...


Works in ALL modern browsers &amp; is more efficient than B64.

Satish is pushing Base64 encoded data to the server using AJAX.   Hopefully he&#039;s using the POST method to avoid URL escaping &#039;%&#039; (huge bloat).  Even with POST, the B64 encoding is being applied TWICE before upload since browsers automatically encode POST data using base64
( this means a 4 to 7 data expansion (almost double) ).

As others have said: DO NOT PRE-OPTIMIZE.  Just develop your site the easiest/fastest way you can, and then run tests to see where it&#039;s ACTUALLY slow.  Chances are your server will already be optimized for your &quot;unoptimized&quot; use case.</description>
		<content:encoded><![CDATA[<p>Oh, boy, this use case is just WRONG.</p>
<p>The problem is that people are confusing &#8220;request&#8221; with &#8220;connection&#8221;.  You want to avoid CONNECTIONS, multiple REQUESTS over one connection is very cheap, and commonplace.  The one TCP connection per request idiom does not exist in practice thanks to HTTP 1.1.</p>
<p>100 small images == 3 or less connections on my Apache/Linux server. </p>
<p>HTTP 1.1 has a &#8220;Connection: Keep-Alive&#8221; header.<br />
This is supported by ALL modern browsers (even mobile) and ALL modern servers (IIS, Tomcat, Apache, etc.)</p>
<p>With Keep-Alive: The browser and server leave the connection open at the &#8220;end&#8221; of a request.  The browser can send additional HTTP 1.1 requests to the server, and the server sends the requested data back over the same single connection.</p>
<p>With static content this translates to Reading all 100 images from disk, and sending them to the client all in one go.</p>
<p>If one of the 100 images changes ONLY that image will be re-sent, the rest will result in a &#8220;No Change&#8221; reply.</p>
<p>Don&#8217;t dynamically generate data unless you have to, and when you do generate &#8220;dynamic&#8221; data make sure to set the caching headers so that multiple requests for the same &#8220;dynamic&#8221; content don&#8217;t require a full request / database lookup / transmission.</p>
<p>Base64 encoding should NOT be used to fix a &#8220;too many connections&#8221; issue, see your server configuration for that.</p>
<p>The &#8220;too many requests&#8221; issue is a misnomer since all modern servers &amp; browsers allow multiple requests over one connection, and the requests are VERY cheap.  </p>
<p>Base64 encoding multiple images into one CSS file is a benefit only when the image data is smaller than an HTTP Request header (mostly never).  Base64 it&#8217;s a 3 to 4 increase of data size, and is only worth using when the base 64 encoded data is smaller than the HTTP Header (very small images &lt; 8&#215;8).</p>
<p>Even this is a silly way do do things.   Lets say I have 100 very small images, I can paste them all into ONE big image, and serve up &quot;palette.png&quot; as a single static image.<br />
To get at the individual images just use CSS.</p>
<p>#my_icon {<br />
  display: inline-block;<br />
  backgroundImage: url(&quot;palette.png&quot;);<br />
  width: 16px; height: 16px;<br />
  backgroundPosition: -48px -160px;<br />
}<br />
#my_icon2{<br />
  /* same as above, with different bkg Pos */<br />
}<br />
&#8212;&#8212;</p>
<p>&#8230;</p>
<p>Works in ALL modern browsers &amp; is more efficient than B64.</p>
<p>Satish is pushing Base64 encoded data to the server using AJAX.   Hopefully he&#8217;s using the POST method to avoid URL escaping &#8216;%&#8217; (huge bloat).  Even with POST, the B64 encoding is being applied TWICE before upload since browsers automatically encode POST data using base64<br />
( this means a 4 to 7 data expansion (almost double) ).</p>
<p>As others have said: DO NOT PRE-OPTIMIZE.  Just develop your site the easiest/fastest way you can, and then run tests to see where it&#8217;s ACTUALLY slow.  Chances are your server will already be optimized for your &#8220;unoptimized&#8221; use case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoimen</title>
		<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/comment-page-1/#comment-12913</link>
		<dc:creator>Stoimen</dc:creator>
		<pubDate>Thu, 22 Apr 2010 08:05:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.stoimen.com/blog/?p=538#comment-12913</guid>
		<description>There are few techniques not only for &lt;img tags, but also for CSS backgrounds. Check out &lt;a href=&quot;http://www.phpied.com/mhtml-when-you-need-data-uris-in-ie7-and-under/&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>There are few techniques not only for &lt;img tags, but also for CSS backgrounds. Check out <a href="http://www.phpied.com/mhtml-when-you-need-data-uris-in-ie7-and-under/" rel="nofollow">this</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kodeart</title>
		<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/comment-page-1/#comment-12912</link>
		<dc:creator>Kodeart</dc:creator>
		<pubDate>Thu, 22 Apr 2010 08:01:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.stoimen.com/blog/?p=538#comment-12912</guid>
		<description>I agree with you. The only thing left is to make the ridiculous IE to show images without too much pain :)</description>
		<content:encoded><![CDATA[<p>I agree with you. The only thing left is to make the ridiculous IE to show images without too much pain <img src='http://www.stoimen.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoimen</title>
		<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/comment-page-1/#comment-12911</link>
		<dc:creator>Stoimen</dc:creator>
		<pubDate>Thu, 22 Apr 2010 06:45:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.stoimen.com/blog/?p=538#comment-12911</guid>
		<description>@Kodeart - it all depends on the specific case. It isn&#039;t a bad idea to store static content on CDN, which in some cases will be better. However the only way to get all 100 images with one request is with base64, isn&#039;t it?</description>
		<content:encoded><![CDATA[<p>@Kodeart &#8211; it all depends on the specific case. It isn&#8217;t a bad idea to store static content on CDN, which in some cases will be better. However the only way to get all 100 images with one request is with base64, isn&#8217;t it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kodeart</title>
		<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/comment-page-1/#comment-12910</link>
		<dc:creator>Kodeart</dc:creator>
		<pubDate>Thu, 22 Apr 2010 06:37:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.stoimen.com/blog/?p=538#comment-12910</guid>
		<description>Interesting technique, what about cache proxy server(s) for static resources (like Varnish, Squid) for these 100+ small images? Not only images, but css, js, swf, template files...

All this about is for webserver calls (100+) which can be optimized with better solutions.

You already said, with cheap and affordable web technologies, a &quot;shared hosting&quot; is a sad story today, so &quot;i have 1 server without ssh and php.ini and without...&quot; is not for ma&#039;n&#039;pa-3-pages website anymore.

My 2 cents.</description>
		<content:encoded><![CDATA[<p>Interesting technique, what about cache proxy server(s) for static resources (like Varnish, Squid) for these 100+ small images? Not only images, but css, js, swf, template files&#8230;</p>
<p>All this about is for webserver calls (100+) which can be optimized with better solutions.</p>
<p>You already said, with cheap and affordable web technologies, a &#8220;shared hosting&#8221; is a sad story today, so &#8220;i have 1 server without ssh and php.ini and without&#8230;&#8221; is not for ma&#8217;n'pa-3-pages website anymore.</p>
<p>My 2 cents.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rithy</title>
		<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/comment-page-1/#comment-12588</link>
		<dc:creator>Rithy</dc:creator>
		<pubDate>Tue, 16 Mar 2010 04:16:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.stoimen.com/blog/?p=538#comment-12588</guid>
		<description>Hi stoimen,

Thank you a lot for your reply and advice!

My image is about 3kb. So I could use it.


Cheer,
Rithy</description>
		<content:encoded><![CDATA[<p>Hi stoimen,</p>
<p>Thank you a lot for your reply and advice!</p>
<p>My image is about 3kb. So I could use it.</p>
<p>Cheer,<br />
Rithy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoimen</title>
		<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/comment-page-1/#comment-12580</link>
		<dc:creator>Stoimen</dc:creator>
		<pubDate>Mon, 15 Mar 2010 11:11:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.stoimen.com/blog/?p=538#comment-12580</guid>
		<description>Hi Rithy,

you definitely have to run some tests to be sure which operation is faster. Using base64 is good for small images and multiple requests, i.e. 100 images each 2KB big. Than you&#039;ve so much requests that even with very small images slows down the page.

When you&#039;ve to store images bigger than a &quot;thumb&quot; size it may be not a good idea. For &quot;wallpaper&quot; size images it&#039;s good to store them as progressive JPGs. 

In your case maybe the converting process from image file -&gt; base64 -&gt; http response may not be the best solution.

My advice is to run test with different scenarios that will answer all your questions.

all the best,
stoimen</description>
		<content:encoded><![CDATA[<p>Hi Rithy,</p>
<p>you definitely have to run some tests to be sure which operation is faster. Using base64 is good for small images and multiple requests, i.e. 100 images each 2KB big. Than you&#8217;ve so much requests that even with very small images slows down the page.</p>
<p>When you&#8217;ve to store images bigger than a &#8220;thumb&#8221; size it may be not a good idea. For &#8220;wallpaper&#8221; size images it&#8217;s good to store them as progressive JPGs. </p>
<p>In your case maybe the converting process from image file -> base64 -> http response may not be the best solution.</p>
<p>My advice is to run test with different scenarios that will answer all your questions.</p>
<p>all the best,<br />
stoimen</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rithy</title>
		<link>http://www.stoimen.com/blog/2009/04/23/when-you-should-use-base64-for-images/comment-page-1/#comment-12579</link>
		<dc:creator>Rithy</dc:creator>
		<pubDate>Mon, 15 Mar 2010 11:00:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.stoimen.com/blog/?p=538#comment-12579</guid>
		<description>Hi,

I&#039;m not sure about the server, currently I have only 1 server and I am not sure how to work with 2 or more databases or servers...

Thanks you. I got it work now. I found that after php wrote the base64 string in a text file, the &#039;+&#039; sign is gone.

But I&#039;ve decided to store as normal image, I&#039;ll encode the normal image into base64 when php load the page.
Because it could be 2 options which can use base64 or normal image and in ie6 doesn&#039;t support base64 image. 

But I&#039;m not sure server will use how much cpu to encode the image...
I&#039;m considering about the usage of upc and ram of the server.

Regards,
Rithy</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I&#8217;m not sure about the server, currently I have only 1 server and I am not sure how to work with 2 or more databases or servers&#8230;</p>
<p>Thanks you. I got it work now. I found that after php wrote the base64 string in a text file, the &#8216;+&#8217; sign is gone.</p>
<p>But I&#8217;ve decided to store as normal image, I&#8217;ll encode the normal image into base64 when php load the page.<br />
Because it could be 2 options which can use base64 or normal image and in ie6 doesn&#8217;t support base64 image. </p>
<p>But I&#8217;m not sure server will use how much cpu to encode the image&#8230;<br />
I&#8217;m considering about the usage of upc and ram of the server.</p>
<p>Regards,<br />
Rithy</p>
]]></content:encoded>
	</item>
</channel>
</rss>

