<?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>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><description>Now, if you have by any chance worked on page load optimizations, you would know how costly each resource download is. The more the number of external resources that you refer to, the more the time it takes for the page load to complete. Typically, web</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><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#2356843</link><pubDate>Tue, 01 May 2007 15:57:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2356843</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You've been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
</description></item><item><title>re: 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#2359054</link><pubDate>Tue, 01 May 2007 18:39:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2359054</guid><dc:creator>Andrew Sazonov</dc:creator><description>&lt;p&gt;Oh, very interesting technique - thank you for your article!&lt;/p&gt;
&lt;p&gt;Btw, I suppose that it's possible have some another trick to eliminate CSS at all - instead of writing it using ordinary CSS rules, I think it's possible to code it directly in JavaScript via manipulations on styles objects (so such file will not rely on specifics of parsers implementation in different browsers). &lt;/p&gt;
&lt;p&gt;Do you think it could be practical? &lt;/p&gt;</description></item><item><title>re: 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#2359055</link><pubDate>Tue, 01 May 2007 18:40:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2359055</guid><dc:creator>DAH</dc:creator><description>&lt;p&gt;Which versions of IE and Firefox? &amp;nbsp;What about other browsers?&lt;/p&gt;</description></item><item><title>re: 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#2368045</link><pubDate>Wed, 02 May 2007 07:09:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2368045</guid><dc:creator>Franklin</dc:creator><description>&lt;p&gt;Combining it all into JS wouldn't be practical, as different browsers have different stylesheet doms, and Opera as of 9 didn't have a stylesheet dom at all&lt;/p&gt;</description></item><item><title>re: 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#2370081</link><pubDate>Wed, 02 May 2007 10:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2370081</guid><dc:creator>Chitty</dc:creator><description>&lt;p&gt;In response to: Andrew Sazonov&lt;/p&gt;
&lt;p&gt;Whist I think this is a fine idea, the problem is anyone with javascript disabled would lose their styles too.&lt;/p&gt;</description></item><item><title>re: 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#2374289</link><pubDate>Wed, 02 May 2007 16:47:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2374289</guid><dc:creator>Jeff Schiller</dc:creator><description>&lt;p&gt;This prevents effective caching. &amp;nbsp;Every time my JS changes, the &amp;quot;CSS&amp;quot; file also has to be downloaded and vice versa. &amp;nbsp;Separating the files allows them to be separately cached.&lt;/p&gt;</description></item><item><title>re: 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#2374583</link><pubDate>Wed, 02 May 2007 17:11:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2374583</guid><dc:creator>Martin Bialasinski</dc:creator><description>&lt;p&gt;So this depends on specific bug-correcting implementations of the parser that may or may not change in the future. And at least the JS parsing will break with a true XHTML-parser.&lt;/p&gt;
&lt;p&gt;In other words: it is a hack and a future liability to support, if it gets used.&lt;/p&gt;
&lt;p&gt;How about serving gzip'ed files, with an expire header one year in the future. The files will get fetched once, after that the browser will use the ones in the cache without checking with the server. And when the path to the files contains a version number, you can easily deploy a new version of the files. &lt;/p&gt;
&lt;p&gt;Standard, proven techniques. Far better than messing around like described in this blog post.&lt;/p&gt;</description></item><item><title>re: 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#2374766</link><pubDate>Wed, 02 May 2007 17:23:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2374766</guid><dc:creator>Jordan</dc:creator><description>&lt;p&gt;By analogy I bet you could also squeeze your HTML into the same file! Just end the comments with a &amp;lt;!-- /* --&amp;gt; line and then start your HTML. --Joking of course.&lt;/p&gt;</description></item><item><title>re: 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#2375317</link><pubDate>Wed, 02 May 2007 18:05:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2375317</guid><dc:creator>GaB</dc:creator><description>&lt;p&gt;Great stuff, thx !&lt;/p&gt;</description></item><item><title>re: 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#2375973</link><pubDate>Wed, 02 May 2007 18:56:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2375973</guid><dc:creator>Sjoerd Visscher</dc:creator><description>&lt;p&gt;It looks like that, for this to work, you have to have a comment start for each line of CSS.&lt;/p&gt;</description></item><item><title>re: 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#2376103</link><pubDate>Wed, 02 May 2007 19:08:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2376103</guid><dc:creator>shivap</dc:creator><description>&lt;p&gt;@Jeff - I agree.&lt;/p&gt;
&lt;p&gt;@Martin - True - this is a hack. &amp;nbsp;However, allowing &amp;lt;!-- tokens in javascript has been there right from the beginning for hiding it from older versions of browsers and i personally believe the browsers would never break that. &amp;nbsp;As for &amp;lt;!-- tokens in CSS, even the w3C CSS validator accepts it positively.&lt;/p&gt;
&lt;p&gt;@Sjoerd - You can remove the newlines from the CSS content so that you need to have &amp;lt;!-- token only once. &amp;nbsp;I do this in my sample app.&lt;/p&gt;</description></item><item><title>re: 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#2376801</link><pubDate>Wed, 02 May 2007 19:57:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2376801</guid><dc:creator>Mike</dc:creator><description>&lt;p&gt;So after reading all of these comments - which method is better?&lt;/p&gt;</description></item><item><title>re: 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#2377092</link><pubDate>Wed, 02 May 2007 20:22:16 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2377092</guid><dc:creator>shivap</dc:creator><description>&lt;p&gt;@Mike - I would suggest that you consider this method only if the page load time bothers you much. &amp;nbsp;If you are already happy with your website's load time all you need to do is to remember that you can come back to this technique when the load time starts bothering you.&lt;/p&gt;
</description></item><item><title>re: 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#2378434</link><pubDate>Wed, 02 May 2007 21:33:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2378434</guid><dc:creator>Anastasiosyal</dc:creator><description>&lt;p&gt;This is an interesting hack, but I would say this is a 'oh look you can also do this', rather than a best practice that people should follow. &lt;/p&gt;
&lt;p&gt;The bandwidth advantage you are gaining is minimal in comparison to the obfuscation overhead you are adding to your files... &lt;/p&gt;
&lt;p&gt;Lets say for example that your js file is 2 kb and css file is another 2kb. &lt;/p&gt;
&lt;p&gt;All you are saying is put them both together in a 4kb file... &lt;/p&gt;
&lt;p&gt;So what is the advantage of this? Advantage is you are skipping one request to the server... This ofcourse comes with its trade offs... One is required to sacrifice code readability, modularity and seperate caching of js and css files simply to squeeze out the overhead of one request of a file from the server. &lt;/p&gt;
&lt;p&gt;I cannot see this a good technique. &amp;nbsp;Js and css are seperate for a reason. One is client side code, the other is design. Keeping design and code seperate makes it all together more maintainable, especially in a team environment where you can have seperate coders and designers... Not to mention that this is not future proof. For future versions of browsers might require the content type of files returned by the server to always be css for css files and js for javascript files due to some security issue that may arise... &lt;/p&gt;
&lt;p&gt;This is an interesting find, but i would suggest that people do not use this in production. &lt;/p&gt;</description></item><item><title>re: 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#2383267</link><pubDate>Thu, 03 May 2007 02:53:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2383267</guid><dc:creator>shivap</dc:creator><description>&lt;p&gt;@Anastasiosyal - thanks for your comment. &amp;nbsp;Your point about readability, maintainability etc. has already been made and answered - i.e., &lt;u&gt;keep the js, css files separate on disk and combine them at runtime&lt;/u&gt; - please check my sample app.&lt;/p&gt;
&lt;p&gt; &amp;nbsp;I agree with your point about future reliability but there are good reasons why browsers won't break their backward compat as HTML comments were allowed into JS and CSS in the first place with a reason.&lt;/p&gt;</description></item><item><title>re: 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#2389745</link><pubDate>Thu, 03 May 2007 11:07:10 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2389745</guid><dc:creator>Craig Francis</dc:creator><description>&lt;p&gt;I would suggest that you should avoid this technique at all costs... this is going with non-standard features which will hopefully be removed from the two (of many) browsers in the future.&lt;/p&gt;
&lt;p&gt;Take for example the huge security hole in IE6/7 where JavaScript can be placed in an image and still be executed... allowing any site with an image upload feature (gallery) to be compromised by an XSS attack... I am hoping that this security hole will be fixed, and in a similar way, it might fix this potential security hole (a site which allows users customise their profile page with their own CSS could allow anyone to upload any JavaScript!)&lt;/p&gt;
&lt;p&gt;For more info, this is a good overview:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://adblockplus.org/blog/the-hazards-of-mime-sniffing"&gt;http://adblockplus.org/blog/the-hazards-of-mime-sniffing&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And for the reality of XSS:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.betanews.com/article/CrossSite_Scripting_Worm_Hits_MySpace/1129232391"&gt;http://www.betanews.com/article/CrossSite_Scripting_Worm_Hits_MySpace/1129232391&lt;/a&gt;&lt;/p&gt;</description></item><item><title>re: 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#2390351</link><pubDate>Thu, 03 May 2007 11:57:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2390351</guid><dc:creator>shivap</dc:creator><description>&lt;p&gt;@Craig - thanks for the pointers. &amp;nbsp;I've posted to sla.ckers.org to figure out whether this technique can be exploited. &amp;nbsp;&lt;/p&gt;
</description></item><item><title>re: 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#2393356</link><pubDate>Thu, 03 May 2007 15:56:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2393356</guid><dc:creator>shivap</dc:creator><description>&lt;p&gt;Copy pasted from sla.ckers.org&lt;/p&gt;
&lt;p&gt;Comment made by trev...&lt;/p&gt;
&lt;p&gt;&amp;quot;I don't think there is anything dangerous about this technique (users who can upload CSS can run JavaScript already, due to expression() and -moz-binding).&amp;quot;&lt;/p&gt;
</description></item><item><title>re: 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#2402128</link><pubDate>Fri, 04 May 2007 03:11:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2402128</guid><dc:creator>shivap</dc:creator><description>&lt;p&gt;Good discussion happening in Ajaxian on this technique... &lt;a rel="nofollow" target="_new" href="http://ajaxian.com/archives/squeeze-css-and-js-into-one-file"&gt;http://ajaxian.com/archives/squeeze-css-and-js-into-one-file&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>CSS and Javascript in a single file</title><link>http://blogs.msdn.com/shivap/archive/2007/05/01/combine-css-with-js-and-make-it-into-a-single-download.aspx#2405257</link><pubDate>Fri, 04 May 2007 08:38:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2405257</guid><dc:creator>Hackszine.com</dc:creator><description>&lt;p&gt;If you're really crazy about optimizing page load time for your website, here's an interesting trick. By abusing some parser quirks in common browsers like Firefox and IE, you can actually combine a CSS file and a Javascript file into...&lt;/p&gt;
</description></item><item><title>re: 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#2425040</link><pubDate>Sat, 05 May 2007 12:56:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2425040</guid><dc:creator>ekang</dc:creator><description>&lt;p&gt;I think this is a good idea&lt;/p&gt;</description></item><item><title>re: 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#2437482</link><pubDate>Sun, 06 May 2007 05:06:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2437482</guid><dc:creator>Nick</dc:creator><description>&lt;p&gt;So, if you're doing this on the server side anyway, why download css and javascript separately from the HTML at all? &amp;nbsp;Just include it in the page requested by the user. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can still keep separate css, js, and html (aspx/ashx) files and then either write a custom control that outputs the css+js into the html or extend the page parser to do it when it compiles your pages.&lt;/p&gt;
&lt;p&gt;My method does break caching, but so does yours.&lt;/p&gt;
&lt;p&gt;In all fairness, your method is a neat hack, but it's not a robust solution to the problem.&lt;/p&gt;</description></item><item><title>re: 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#2438942</link><pubDate>Sun, 06 May 2007 07:02:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2438942</guid><dc:creator>shivap</dc:creator><description>&lt;p&gt;@Nick - Combining js and css and keeping them as an external resource, I agree that it will need to be refreshed every time the js or the css changes, but then how frequently do you expect such changes to happen on a production site? &amp;nbsp;As for inlining them into the HTML, I think the disadvantages here are too obvious to even write further.&lt;/p&gt;
</description></item><item><title>re: 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#2947824</link><pubDate>Mon, 28 May 2007 19:12:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2947824</guid><dc:creator>Sergey Koksharov</dc:creator><description>&lt;p&gt;Wow, its really cool tips! Thanks a lot!&lt;/p&gt;</description></item><item><title>re: 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#3223720</link><pubDate>Mon, 11 Jun 2007 10:19:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3223720</guid><dc:creator>Dead Krolik</dc:creator><description>&lt;p&gt;Thanks a lot. Really good tips.&lt;/p&gt;</description></item><item><title>link</title><link>http://blogs.msdn.com/shivap/archive/2007/05/01/combine-css-with-js-and-make-it-into-a-single-download.aspx#9550482</link><pubDate>Wed, 15 Apr 2009 13:22:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9550482</guid><dc:creator>PukiWiki Plus! (PukiWiki/TrackBack 0.4)</dc:creator><description>&lt;p&gt;link 【レポート】IE8で互換性の実現や新機能を利用するには? - MSがサイト管理者向けガイド (1) IE8準拠のための見直しポイント | パソコン | マイコミジャーナル -- 2009-04-15 (水) 19:20:52 １つのファイルにJavaScriptとCSSをまとめて記述する方法 phpspot開発日...&lt;/p&gt;
</description></item></channel></rss>