NOTE: IncludeHandling has been moved to this fork:


This project was first started by Peter Mounce in GitHub (where you can still see the original code) and then moved to MvcContrib and renamed from IncludeCombiner to IncludeHandling.

IncludeHandling is a resuable component written for ASP.NET MVC that is for handling static file-includes like CSS and Javascript in a best-practise way, that can be dropped into your own ASP.NET MVC web project, configured, and used with a minimum of effort.


  • Mashes together the includes on a page to a single request, following YSlow! guideline for same (minimise number of requests necessary to load page)
  • Minifies the include-combination (using the YUICompressor); strips comments and whitespace to reduce file-weight on the wire
  • If the browser accepts compression, compresses (gzip/deflate) the response
  • Appends cache-policy headers to the response to control client-side caching
  • Does all this at run-time with no configuration or build complexity overhead

Also, it's configurable so you can control:
  • The path that the combiner-controller's action happens at, per include-type (CSS/JS)
  • The minification options, per include-type
  • The default length of time to cache the include-combination at the client-side for
  • Which compression to pick when a choice is accepted
  • There's a DebugFilterAttribute responsible for switching operation between debug and release-mode, and an HtmlHelper extension method to test whether we're in debug-mode (it reacts to a debug=1 or debug=0 in the querystring, and sets a debug cookie if debug=1; removes it if debug=0)

And finally:
  • It's pluggable, so you can replace collaborating components (for example if you wanted to replace the in-memory static storage with a cache-backed IIncludeStorage)
  • It has a demo
  • It has benchmarks (see Demo.Site)
  • It's highly covered in unit-tests - see -> MvcContrib.IncludeHandling not yet
  • It has a page that tells you which includes and combinations are registered; the index action on IncludeController

How to use it

  • Unzip the distribution (there's no distribution right now, download fork sources)
  • Reference MvcContrib.IncludeHandling.dll in your web-project
  • Register services in your IoC container (the sample code creates it's own DIY container implementing IDependencyResolver, but it's just a sample):
    • IHttpContextProvider -> MvcContrib.HttpContextProvider
    • IKeyGenerator -> MvcContrib.IncludeHandling.KeyGenerator
    • IIncludeReader -> MvcContrib.IncludeHandling.FilesystemIncludeReader
    • IIncludeStorage -> MvcContrib.IncludeHandling.StaticIncludeStorage
    • IIncludeCombiner -> vcContrib.IncludeHandling.IncludeCombiner
  • Ensure your web-project's ControllerFactory can create the IncludeController when it's required to. This may require replacing the default ControllerFactory with an IoC-aware one. MvcContrib main project has some of them.
  • (optional) Create ~/Views/Include/Index.aspx and copy MvcContrib.Samples.IncludeCombining/Views/Include/Index.aspx's content to it
  • (optional) Configure it via web.config via following options (where more than one choice exists, default value is given first):
  <css path="~/include/css/xxx.css" compressionOrder="gzip,deflate" cacheFor="365:00:00:00.000" minify="true|false">
      <options verbose="false|true" obfuscate="false|true" preserveSemiColons="true|false" disableOptimizations="false|true" lineBreakAt="{int}" />
  <js path="~/include/js/xxx.js" compressionOrder="gzip,deflate" cacheFor="365:00:00:00.000" minify="true|false">
      <options lineBreakAt="{int}" compressionType="Hybrid|StockYuiCompressor|MichaelAshRegexEnhancements" />

Last edited Feb 5, 2011 at 6:26 PM by mcliment, version 2


No comments yet.