CacheTag

Simple and efficient JavaScript and CSS minification for ASP.NET MVC

CacheTag

Simple and efficient JavaScript and CSS minification for ASP.NET MVC

What it does

CacheTag helps speed up your page load times in a number of ways.

  • Reduces the number of HTTP requests by combining resources
  • Makes resources quicker to download thanks to minification
  • All resources are hashed, preventing clients from using old resources
  • Since any change creates a new hash, resources can be cached aggressively

Compared to the competition

CacheTag provides a number of benefits compared to other similar frameworks.

  • It's real easy to use, see the examples
  • It's flexible because it works with generic lists, no custom bundle classes
  • It's faster because it only compiles resources when needed, even in debug mode
  • Built to be extendable, use the source Luke!

Example Razor code

Let's say you want to include a couple of CSS files and JavaScripts, you can try this..

@Html.RenderStyles(new []
{
	"~/CSS/Reset.css",
	"~/CSS/Site.less"
})
@Html.RenderScripts(new []
{
	"~/Scripts/jquery-1.7.1.js",
	"~/Scripts/app.coffee"
})

.. and that's it. Check out what this would produce below.

Resulting HTML in release mode

The example above would minify and combine the resources, calculate a unique hash and output HTML similar to this.

<link rel="stylesheet" type="text/css" href="/_cachetag/e4dddf2cdd91d693e023cdc5dc0b56d8664766db.css" />
<script src="/_cachetag/80e9e6fc43c6644ea9badec99eb5c6cbec87c4b0.js" type="text/javascript"></script>

Resulting HTML in debug mode

In debug mode however, it would still calculate hashes of all resources but link to them individually, each with a query parameter containing the hash, this is to ease debugging but still prevent you from accidentally using stale scripts or CSS.

<link rel="stylesheet" type="text/css" href="/CSS/Reset.css" />
<link rel="stylesheet" type="text/css" href="/CSS/Site.less" />
<script src="/Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="/Scripts/app.coffee" type="text/javascript"></script>