Skip to content

chaliy/aspnet-underscore-bundler

Repository files navigation

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.

Features

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

Example

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.AddFile("~/scripts/app/main.html");
appJs.AddFile("~/scripts/app/example2.html");      
appJs.AddFile("~/scripts/app/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();

BundleTable.Bundles.Add(appJs);

Complete example is SampleWebApp project in sources.

Installation

PM> Install-Package UnderscoreBundler

License

Licensed under the MIT

About

ASP.NET MVC4 bundler for compiled Underscore templates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages