Skip to content


Subversion checkout URL

You can clone with
Download ZIP
ASP.NET MVC4 bundler for compiled Underscore templates
JavaScript C# Other

ASP.NET Underscore.js Templates Bundler

Management of the templates for your JavaScript app could be pain. Of course, there are few solutions out there. This library is another solution :). Okay, sort of. Really this is just better implementation of Anton Samarskyy's idea.

So main idea of this library is about to keep templates as HTML files near of your JS files, but serve them as single file to reduce requests. What is more interesting is that we can go further and precompile templates so we can serve templates as single js file with our app scripts. Stay turned.

Now about implementation. ASP.NET MVC 4 introduced bundling support. In simple words this is actually means combining (and minifying) many resource files (JavaScript, CSS) to the single file to reduce number of requests. This is what we actually use.


  1. Bundle HTML templates to the single file
  2. Precompile Underscore templates (ver 1.5.1)


Assuming that you have folder structure like this

Folder structure

bundle configuration will be

// Create app bundle: 
//    main.html and example2.html are underscore templates
//    app.js is our simple application
var appJs = new Bundle("~/scripts/app.js");


appJs.Transform = new NoTransform("text/javascript; charset=utf-8");    
//appJs.Transform = new JsMinify(); // You can minify bundle if you want
appJs.Builder = new CompiledUndrescoreTemplatesBundler();


Complete example is SampleWebApp project in sources.


PM> Install-Package UnderscoreBundler


Licensed under the MIT

Something went wrong with that request. Please try again.