<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>My experiments with .Net</title><link>http://blogs.msdn.com/shivap/default.aspx</link><description>This is where I log my learnings, hacks, surprises and frowns regarding .Net and associated technologies...</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Moving my blog</title><link>http://blogs.msdn.com/shivap/archive/2008/03/06/moving-my-blog.aspx</link><pubDate>Thu, 06 Mar 2008 13:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8070208</guid><dc:creator>shivap</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/shivap/comments/8070208.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shivap/commentrss.aspx?PostID=8070208</wfw:commentRss><description>&lt;P&gt;Hi there, I've decided to move my technical blog over to &lt;A class="" href="http://www.cognitivecoding.com/" mce_href="http://www.cognitivecoding.com"&gt;Cognitive Coding&lt;/A&gt;.&amp;nbsp; Also, hoping to keep it more active compared to this one... so watch out!&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8070208" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shivap/archive/tags/Personal/default.aspx">Personal</category></item><item><title>Automate packing multiple images into one and CSS generation</title><link>http://blogs.msdn.com/shivap/archive/2007/06/23/automate-packing-multiple-images-into-one-and-css-generation.aspx</link><pubDate>Sat, 23 Jun 2007 07:40:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3473214</guid><dc:creator>shivap</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/shivap/comments/3473214.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shivap/commentrss.aspx?PostID=3473214</wfw:commentRss><description>
&lt;p&gt;CSS sprites is a technique used to minimize the number of external image downloads required for a web page to load completely.&amp;nbsp; If you aren't already aware of the technique, refer to &lt;a href="http://www.alistapart.com/articles/sprites/" mce_href="http://www.alistapart.com/articles/sprites/" target="_blank"&gt;this&lt;/a&gt; excellent article by Dave Shea.&lt;/p&gt;
 
&lt;p&gt;Now when you get excited by this technique and&amp;nbsp;desire your web-pages to benefit from it, the first blocker you'll face on the road is to figure out an image processing tool to pack the images and also create the corresponding CSS.&amp;nbsp; This is also a very cumbersome job and would drive you nuts whenever you need to change or add images to your web page.&amp;nbsp; So, how good it'll be if you have a tool that takes in the images, packs them and generates the CSS automatically?&amp;nbsp; Well, you have it.&lt;/p&gt;
 
&lt;p&gt;With this&amp;nbsp;post i'm attaching the&amp;nbsp;visual studio project&amp;nbsp;I developed for this purpose.&amp;nbsp; Just build it and you'll have the tool for you to play with.&amp;nbsp; The tool will generate comprehensive usage information that'll help you get started.&amp;nbsp; I'm also attaching a sample web project that uses the tool to display images onto a demo page.&lt;/p&gt;
 
&lt;p&gt;The tool accepts images of type GIF and PNG and converts them to a single image of type GIF or PNG-8.&amp;nbsp; PNG-8 images have the advantage of being smaller compared to GIF images and hence I would strongly recommend that you generate PNG-8 out of the tool.&amp;nbsp; Also, all browsers display PNG-8 images without any problem, so you needn't think twice.&amp;nbsp; To generate PNG-8, the image packer tool internally makes use of a GIF to PNG conversation/optimization tool called PNGOUT.&amp;nbsp; You can download it &lt;a href="http://advsys.net/ken/util/pngout.htm" mce_href="http://advsys.net/ken/util/pngout.htm" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;
 
&lt;p&gt;I should thank&amp;nbsp;Morgan Skinner for his excellent &lt;a href="http://msdn2.microsoft.com/en-us/library/aa479306.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/aa479306.aspx" target="_blank"&gt;MSDN article&lt;/a&gt; with source code&amp;nbsp;on color quantization.&amp;nbsp; I made use of the Octree Quantization code in my image packer tool.&lt;/p&gt;
 
&lt;p&gt;You can use the image packer source code or tool wherever and however you like.&amp;nbsp; You can also make modifications to the tool and use it for any purpose.&lt;/p&gt;
 
&lt;p&gt;One final word, while I've been using this tool for quite some time now and it has been working without glitches, there might be some hidden bugs.&amp;nbsp; I request you to report the bugs and I'll be more than happy to fix them.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Notes:&lt;br&gt;&lt;/b&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The PNGOUT tool has problems dealing with paths with spaces.&amp;nbsp; Make sure that the image output path doesn't have any spaces (in the absolute path).&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;Share this post&lt;/b&gt;:&amp;nbsp;&lt;/p&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blogs.msdn.com/shivap/archive/2007/06/23/automate-packing-multiple-images-into-one-and-css-generation.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blogs.msdn.com/shivap/archive/2007/06/23/automate-packing-multiple-images-into-one-and-css-generation.aspx" alt="kick it on DotNetKicks.com" border="0"&gt;&lt;/a&gt;
&lt;script type="text/javascript"&gt;
digg_url = 'http://blogs.msdn.com/shivap/archive/2007/06/23/automate-packing-multiple-images-into-one-and-css-generation.aspx';
&lt;/script&gt;
&lt;script src="http://digg.com/tools/diggthis.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script&gt;reddit_url='http://blogs.msdn.com/shivap/archive/2007/06/23/automate-packing-multiple-images-into-one-and-css-generation.aspx'&lt;/script&gt;
&lt;script&gt;reddit_title='Automate packing multiple images into one and CSS generation'&lt;/script&gt;
&lt;script src="http://reddit.com/button.js?t=2" language="javascript"&gt;&lt;/script&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=3473214" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/shivap/attachment/3473214.ashx" length="117404" type="application/zip" /><category domain="http://blogs.msdn.com/shivap/archive/tags/Performance/default.aspx">Performance</category></item><item><title>Combine CSS with JS and make it into a single download!</title><link>http://blogs.msdn.com/shivap/archive/2007/05/01/combine-css-with-js-and-make-it-into-a-single-download.aspx</link><pubDate>Tue, 01 May 2007 15:10:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2356278</guid><dc:creator>shivap</dc:creator><slash:comments>26</slash:comments><comments>http://blogs.msdn.com/shivap/comments/2356278.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shivap/commentrss.aspx?PostID=2356278</wfw:commentRss><description>&lt;P&gt;Now, if you have by any chance worked on page load optimizations, you would know how costly each resource download is.&amp;nbsp; The more the number of external resources that you refer to, the more the time it takes for the page load to complete.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Typically,&amp;nbsp;web pages refer to many external CSS and JS files and hence incur many resource downloads.&amp;nbsp; The advice from the PLT (page load time) gurus is to combine all the CSS files into one and all the JS files into one so as to reduce the number of resource downloads to just two.&amp;nbsp; This, without any doubt, would help boost your PLT.&lt;/P&gt;
&lt;P&gt;If you feel that two downloads still isn't the best,&amp;nbsp;I concur.&amp;nbsp;&amp;nbsp;In this&amp;nbsp;post,&amp;nbsp;we'll look at a technique to combine CSS with JS and get the resource download count to one!&amp;nbsp; I discovered this technique while desperately trying to improve the page load time for the pages in &lt;A href="http://www.officelive.com/" target=_blank mce_href="http://www.officelive.com"&gt;Microsoft Office Live&lt;/A&gt;.&amp;nbsp; Read on...&lt;/P&gt;
&lt;P&gt;The technique relies on how CSS and JS parser&amp;nbsp;behaves in IE and Firefox.&amp;nbsp; &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When the CSS parser encounters a HTML comment token (&amp;lt;!--) in CSS content, the token gets ignored. &lt;/LI&gt;
&lt;LI&gt;When the JS parser encounters a HTML comment token (&amp;lt;!--) in JS content, the token is treated similar to the line comment (//) and hence the rest of the line following the HTML comment token gets ignored&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Look at the below JS+CSS code snippet...&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;!-- /*&lt;BR&gt;function t(){}&lt;BR&gt;&amp;lt;!-- */&lt;BR&gt;&amp;lt;!-- body { background-color: Aqua; }&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;When the CSS parser parses the above content, the HTML comment tokens would be dropped&amp;nbsp;and the snippet would become equivalent to the one&amp;nbsp;below...&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;/*&lt;BR&gt;function t(){}&lt;BR&gt;*/&lt;BR&gt;body { background-color: Aqua; }&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;As you can see above, the CSS parser will get to see only the CSS code and the script code would appear to be within the comments (/* ... */).&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In similar lines, when the JS parser parses the content, the HTML comment tokens would be treated as line comments (//) and hence the code snippet would become equivalent to the one below...&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;//&amp;nbsp;/*&lt;BR&gt;function t(){}&lt;BR&gt;//&amp;nbsp;*/&lt;BR&gt;//&amp;nbsp;body { background-color: Aqua; }&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;As you can see above, the JS parser will get to see only the script code and the rest of the contents would look&amp;nbsp;like comments.&lt;/P&gt;
&lt;P&gt;You can refer to the above content in both the SCRIPT and LINK tags in your HTML page.&amp;nbsp; For e.g.,&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;lt;link type="text/css" rel="stylesheet" href="test.jscss" /&amp;gt;&lt;BR&gt;&amp;lt;script type="text/javascript" language="javascript" src="test.jscss"&amp;gt;&amp;lt;/script&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Note above that both the tags refer to the same source and hence it would be downloaded once and used as appropriate (as CSS and SCRIPT).&lt;/P&gt;
&lt;P&gt;To round it off, there is just one more thing that you need to take care of - the response content type - it needs to be set to &lt;FONT face="courier new"&gt;&lt;B&gt;*/*&lt;/B&gt;&lt;/FONT&gt; in order to&amp;nbsp;affirm to&amp;nbsp;Firefox that the contents can be&amp;nbsp;treated as anything as appropriate.&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;I've attached a sample project (created with VS 2005 SP1) that demonstrates this technique.&amp;nbsp; Enjoy!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;B&gt;Update&lt;/B&gt;: (put in place due to popular misconception) In the &lt;U&gt;actual implementation you will have the JS and CSS files separately on disk&lt;/U&gt;.&amp;nbsp; At runtime, you'll have to combine them by adding the HTML comments appropriately and serve with the correct content type and cache headers.&amp;nbsp; You should also remember the dynamically built content so that you don't need to rebuild them for each request.&amp;nbsp; Please check out the attached sample app.&amp;nbsp; This will ensure that you don't compromise on the readability, maintainability etc. while at the same time taking advantage of the reduced number of network calls.&lt;BR&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Note(s)&lt;/SPAN&gt;:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;If the JS contains any multi line comments it should be removed before combining with the CSS using this technique. &lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;This technique has been tested positive on IE6, IE7 and Firefox 2.0.&amp;nbsp; It &lt;B&gt;may &lt;/B&gt;work on other browsers off the shelf or may need minor tweaks.&lt;/LI&gt;&lt;/UL&gt;&lt;BR&gt;&lt;B&gt;Share this post&lt;/B&gt;: &lt;A title="Post http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx" href="mailto:&amp;amp;body=I%20was%20reading%20this%20article%20and%20thought%20that%20you%20might%20like%20this:http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx&amp;amp;subject=Combine%20CSS%20with%20JS%20and%20make%20it%20into%20a%20single%20download%21" target=_blank&gt;email it!&lt;/A&gt; | &lt;A title="Post http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx" href="http://del.icio.us/post?url=http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx&amp;amp;;title=Combine%20CSS%20with%20JS%20and%20make%20it%20into%20a%20single%20download%21" target=_blank&gt;bookmark it!&lt;/A&gt; | &lt;A title="Post http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx" href="http://digg.com/submit?phase=2&amp;amp;url=http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx&amp;amp;title=Combine%20CSS%20with%20JS%20and%20make%20it%20into%20a%20single%20download%21" target=_blank&gt;digg it!&lt;/A&gt; | &lt;A title="Post http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx" href="http://reddit.com/submit?url=http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx&amp;amp;title=Combine%20CSS%20with%20JS%20and%20make%20it%20into%20a%20single%20download%21" target=_blank&gt;reddit!&lt;/A&gt; | &lt;A title="Post http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx" href="http://www.dotnetkicks.com/kick/?url=http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx&amp;amp;title=Combine%20CSS%20with%20JS%20and%20make%20it%20into%20a%20single%20download%21" target=_blank&gt;kick it!&lt;/A&gt; | &lt;A title="Post http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http%3A%2F%2Fblogs.msdn.com%2Fshivap%2Farchive%2F2007%2F05%2F01%2Fcombine-css-with-js-and-make-it-into-a-single-download.aspx&amp;amp;title=Combine%20CSS%20with%20JS%20and%20make%20it%20into%20a%20single%20download%21" target=_blank&gt;live it!&lt;/A&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2356278" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/shivap/attachment/2356278.ashx" length="20510" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/shivap/archive/tags/Asp.Net/default.aspx">Asp.Net</category><category domain="http://blogs.msdn.com/shivap/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://blogs.msdn.com/shivap/archive/tags/Performance/default.aspx">Performance</category></item><item><title>My intro...</title><link>http://blogs.msdn.com/shivap/archive/2007/04/30/my-intro.aspx</link><pubDate>Mon, 30 Apr 2007 17:08:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2339965</guid><dc:creator>shivap</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/shivap/comments/2339965.aspx</comments><wfw:commentRss>http://blogs.msdn.com/shivap/commentrss.aspx?PostID=2339965</wfw:commentRss><description>&lt;p&gt;&amp;nbsp; Welcome to my blog!&amp;nbsp; My name is Shiva and I work for the &lt;a href="http://www.officelive.com" title="Microsoft Office Live" target="_blank" mce_href="http://www.officelive.com"&gt;Microsoft Office Live&lt;/a&gt; team.&amp;nbsp; My focus areas include C#, Asp.Net, JavaScript, Ajax and page load performance optimizations.&lt;/p&gt;&lt;p&gt;&amp;nbsp; In this blog space, I plan to share my learnings being gained as part of my work in &lt;a href="http://www.officelive.com" title="Microsoft Office Live" target="_blank" mce_href="http://www.officelive.com"&gt;Microsoft Office Live&lt;/a&gt;.&amp;nbsp; Hope you find it useful...&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2339965" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/shivap/archive/tags/Personal/default.aspx">Personal</category></item></channel></rss>