Feature Suggestion: GZip'd Content-type

Nov 9, 2007 at 1:33 PM
Howdy,

I dig your project, but I think it's a great idea if you add optional gzip' compression for fast delivery to clients.

Not sure what you'd do if the client didnt support gzip, maybe you could store both uncompressed and compressed consolidated files in memory.

-V
Coordinator
Dec 13, 2007 at 4:28 PM

CVertex wrote:
Howdy,

I dig your project, but I think it's a great idea if you add optional gzip' compression for fast delivery to clients.

Not sure what you'd do if the client didnt support gzip, maybe you could store both uncompressed and compressed consolidated files in memory.

-V


Hey Vijay,

Thanks for you feedback, I really appreciate it. I apologize because I am really behind in the documentation, so there are several features to this library which are not very obvious. One of them is that if you are building your website using MSBuild, you can use an MSBuild task to pre-consolidate your scripts/css to static files that will then be included on your page instead of the .jsx and .cssx virtual files. The .jsx and .cssx handlers are optimized for a development environment, and were really never made for a production environment ( e.g. they do not emit expires headers so browsers will always request the resource every time...although they will only get a 304 if the content hasn't been updated). The primary motivation of the dynamic handlers was to allow you to use your content in a consolidated way (as they will be in production) without needing to manually build or run an external tool every time you modified a .js or .css file.

Once you have your files in static .js or .css format, then you can just configure IIS to serve up .js and .css files in a GZip format and it should just work. That is what we do where I work and it is working really well.

Here is how to use the MSBuild task:

1. In the MSBuild file for your website, import the PreConsolidateResources task by adding the following line:

  <UsingTask TaskName="PreConsolidateResources" AssemblyFile=".\Bin\AlmWitt.Web.ResourceManagement.dll"/>
Notice the AssemblyFile property points to the dll in your bin directory of your website. Depending on where your MSBuild file resides, you may need to adjust the relative path accordingly.

2. After you have imported the task, you need to call it in the AfterBuild target of your build file. It will look something like this:

<Target Name="AfterBuild">
    <PreConsolidateResources WebRoot="$(OutputPath)" />
</Target>
Note that I have tested this and it works great if you are using a Web Deployment Project. It should also work in the csproj file of a Web Application Project, however, you probably don't want it running when you are developing in Visual Studio (you only want to run it when you are doing an official build). To make sure it doesn't run when building in the IDE, you can put a Condition on it like this:

<PreConsolidateResources WebRoot="$(OutputPath)" Condition="$(BuildingInsideVisualStudio)!='true'" />
I hope this helps, and feel free to contact me if you have any more questions.