Get Combres to work with ASP.NET

After having some problems with getting SquishIt to work with JavaScript closures, we decided to give Combres a try. However, while SquishIt works right out of the box, Combres needs to be configured a bit. This page describes how.

In short, you need to:

  • Create a custom Combres configuration file
  • Add the following to web.config:
    • A Combres configSection tag
    • A Combres section tag (which you point to the Combres config file)
    • Two httpModule tags
  • Add RouteTable.Routes.AddCombresRoute(“Combres Route”); to the Global.asax Application_Start method
  • Add <%= WebExtensions.CombresLink(“…”) %>wherever you want to add JS or CSS tags.

With SquishIt, you only need to add a bundle tag to your page, which is way easier. Still, Combres is said to perform better compression…and handles JavaScript closures without any problems.

With Combres up and running, I noticed that it does not work with IIS7 / Integrated pipeline mode. If you run into this problem, remove all mumbo jumbo content in within the Combres section tag, so that it looks like this:

<section name=”combres” type=”Combres.ConfigSectionSetting” />

Then, instead of:

<httpModules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
	System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
	PublicKeyToken=31BF3856AD364E35"/>
        <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule,
	System.Web.Routing, Version=3.5.0.0, Culture=neutral,
	PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

You also need to add the modules to the system.webServer/modules tag, since that is the one used by IIS7  (keep the ones above as well, though):

<modules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
	System.Web.Extensions, Version=3.5.0.0, Culture=neutral,
	PublicKeyToken=31BF3856AD364E35"/>
        <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule,
	System.Web.Routing, Version=3.5.0.0, Culture=neutral,
	PublicKeyToken=31BF3856AD364E35"/>
</modules>

If you follow these steps, Combres should work.

Advertisements