Please wait....

AzureBundling

This package allows Bundles to be created using files from Azure. The Bundles can be either CSS or JS Bundles that are minified and a seperate Gzip compressed file will be created as well. It sets the CdnPath of the Bundle to the compressed file if the Request Accepts gzip. Otherwise the CdnPath is set to the non-compressed file. The bundle is also created in memory for complete fallback protection. You declare your Bundle as you normally would. Instead of StyleBundle or ScriptBundle use JSBundle or CSSBundle. Declaration includes Bundle virtualPath - "~/bundles/common" and container - "AzureContainer". The bundle will be minified and saved back to Azure with the correct extension added. (.css or .js) A folder will be created inside your folder named compressed where a gzip compressed file will be created with the same name. The file is then cached in-memory and served to the client with the CdnPath - cdn.mysite.com/AzureContainer/bundles/compressed/common.js Automatically falls back to in-memory file if cdn fails. Creates a cache dependency so if you change any file in the bundle on Azure, the bundle will be recreated depending on the CachePollTime. Set the BundleCacheTTL to whatever far off time you want and changes will force invalidation to all requests.

Getting started

Have a look at the files in dev tools of any browser. You will see that the files are coming from my cdn. They are actually Bundles built on app start. It only took me 15 minutes to have this site up and running with Azure Bundling. Very simple to implement. Just download the nuget package, set up the web.config or config.json files with your info and add bundles to BundleConfig.cs. Make sure your files exist on Azure in the paths you declare.

Web.config

<add key="CdnPath" value="your cdn or Azure storage url" />

<add key="SecureCdnPath" value="your secure cdn or Azure storage url" />

<add key="AzureAccountName" value="your account name" />

<add key="AzureAccessKey" value="your access key" />

<add key="BundleCacheTTL" value="integer value in seconds for cache time to live" />

<add key="CachePolltime" value="integer value in seconds how often to poll for file changes" />

<add key="UseCompression" value="NEW boolean value to turn off gzip compression because Azure CDN claims to support it now" />

config.json

{

"AzureAccountName": "your account name",

"AzureAccessKey": "your access key",

"CdnPath": "your cdn or Azure storage url",

"SecureCdnPath": "your secure cdn or Azure storage url",

"CachePollTime": "integer value in seconds how often to poll for file changes",

"BundleCacheTTL": "integer value in seconds for cache time to live"

"UseCompression": "NEW boolean value to turn off gzip compression because Azure CDN claims to support it now"

}

BundleConfig.cs

using System.Web;

using System.Web.Optimization;

using Byaltek.com;

namespace hello.world

{

public class BundleConfig

{

public static void RegisterBundles(BundleCollection bundles)

{

BundleTable.Bundles.Clear();

bundles.UseCdn = true;

BundleTable.EnableOptimizations = true;

BundleTable.VirtualPathProvider = new StorageVirtualPath(AzureContainer);

bundles.Add(new JSBundle("~/your virtual path/jqueryVal", "your folder").Include("~/your folder path/jquery.validate.js", "~/your folder path/jquery.validate.unobtrusive.js"));

bundles.Add(new JSBundle("~/your virtual path/modernizr", "your folder").Include("~/your folder path/modernizr-2.6.2.js"));

bundles.Add(new JSBundle("~/your virtual path/jquerycombined", "your folder").Include( "~/your folder path/jquery-2.1.3.js", "~/your folder path/bootstrap.js", "~/your folder path/respond.js"));

bundles.Add(new CSSBundle("~/your virtual path/site", "your folder").Include( "~/your folder path/bootstrap.css", "~/your folder path/site.css"));

Use the following example if you don't want to use config files.

BundleTable.VirtualPathProvider = new StorageVirtualPath(AzureContainer, AzureAccountName, AzureAccessKey, CachePollTime);

var jquerycombined = new JSBundle("~/bundles/jquerycombined", AzureContainer, AzureAccountName, AzureAccessKey, CdnPath, SecureCdnPath, BundleCacheTTL).Include( "~/your folder path/jquery-2.1.3.js", "~/your folder path/bootstrap.js", "~/your folder path/respond.js"));

bundles.Add(jquerycombined);

}

}

}

Click the buttons below to see more about Azure Bundling.

github nuget