ScriptResource.axd with MbCompression

912 views Asked by At

I'm using MbCompression library and I'm want to know - does MbCompression minifies ScriptResource.axd? And are there any tools that can minimify ScriptResource.axd at runtime with minimum changes to web.config?

1

There are 1 answers

5
Matt Wrock On BEST ANSWER

I'm not familiar with MbCompression, but do take a look at RequestReduce. This is an OSS project of mine and I believe it does exactly what you want: minifies/combines css and javascript at runtime. Unlike other frameworks, RequestReduce requires no code changes, no rearrangement of scripts and css and VERY little config. All the config necessary is to add the module. Here is all you really need in your config:

<system.web>
 <httpModules>
  <add name="RequestReduce" type="RequestReduce.Module.RequestReduceModule, RequestReduce"/>
 </httpModules>
</system.web>
<system.webServer>
 <modules>
  <validation validateIntegratedModeConfiguration="false"/>
  <add name="RequestReduce" type="RequestReduce.Module.RequestReduceModule, RequestReduce"/>
 </modules>
</system.webServer>

That's it and no extra code. There are a bunch of options you have access to to turn various things on and off and configure cache syncing across multiple servers or include a CDN host in your urls. But for an out of the box solution, just the above should be necessary.

It will look for any script url and will minify it and merge it with adjacent script tag contents as long as the following are true:

  1. The mime type of the url is a valid javascript mime type. So ScriptResources and WebResources should be caught.
  2. The url does not have a no-cache or no-store cache-control header.
  3. The url does not have a max-age or expires header less than a week.

I have heard accounts of people complaining that webresource.axd or scriptresource.axd get sent to the browser with no-cache set. This may not be an issue for you but if you see this happening and the lack of caching is not intentional, you can add this to your web.config:

<staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="180.00:00:00" cacheControlCustom="public" />
</staticContent>

In addition, it can automatically sprite any background images, optimize their PNG compression and it uses best practices when serving cache headers for its cached css/javascript/sprites.

This framework is currently used at Microsoft by MSDN and Technet galleries.

You can either install via Nuget (suggested) or download from http://www.requestreduce.com.