Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets series.
In this instalment we will be discussing another similar technique that was previously discussed in the first article.
The previous process discussed a method to do this for your .Net website automatically by parsing the outputted HTML for your stylesheets and scripts, combining them into one string each, saving the strings to server cache and finally rendering them through a gzipped output.
This is all done by utilizing a .Net HttpModule.
I thought it would be the perfect solution, but have since found out otherwise. While the methodology involved remains the same, the delivery method is what is changing. I have found that if you utilize Master Pages (or have developed a highly customizable CMS system like myself - shameless plug = check my bio), this method simply does not work.
Thus, I set myself the task of making something work.
What I found was that by using a Response.Filter on the IO.Stream of the HTML rendered, we can accomplish the same goals, without any modifications to your web.config file, and without the use of an HttpModule.
Default3.aspx is the same file as Default.aspx, except it does not contain the filter in the code behind.
The biggest thing to note here is the number of requests, and keep in mind this testing is done by VS2008's debugging.
'Does the browser accept content encoding?
#Region " Required Properties by the IO.Stream Interface "
#Region " Internal Properties "
#Region " Required by IO.Stream "
' Need to put the New and Improved CSS string somewhere!
' Need to put the New and Improved JS Somewhere!
make sure you run this in a dev environment so you can tweak it to your needs before deploying.