Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

ASP.NET MVC4 bundler for compiled Underscore templates

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .nuget
Octocat-spinner-32 docs
Octocat-spinner-32 src
Octocat-spinner-32 .gitattributes
Octocat-spinner-32 .gitignore
Octocat-spinner-32 LoadEnv.ps1
Octocat-spinner-32 PushToNuget.ps1
Octocat-spinner-32 README.md
Octocat-spinner-32 UnderscoreBundler.sln
Octocat-spinner-32 UnderscoreBundler.sln.DotSettings
README.md

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

Something went wrong with that request. Please try again.