Skip to content

Instantly share code, notes, and snippets.

@jchandra74 jchandra74/fingerprint.cs

Last active Aug 29, 2015
What would you like to do? good config and practices
//Stolen from @mkristensen
//Use to bust static content like .js and .css when they changed.
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
public class Fingerprint
public static string Tag(string rootRelativePath)
if (HttpRuntime.Cache[rootRelativePath] == null)
var absolute = HostingEnvironment.MapPath("~" + rootRelativePath);
var date = File.GetLastWriteTime(absolute);
var index = rootRelativePath.LastIndexOf('/');
var result = rootRelativePath.Insert(index, "/v-" + date.Ticks);
HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute));
return HttpRuntime.Cache[rootRelativePath] as string;
<!-- ensure gzip on both static and javascript, etc. -->
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<!-- long expiry cache for static contents -->
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="365.00:00:00" />
<!-- url rewriting to strip of the versioning to break the long expiry cache on static contents -->
<rule name="fingerprint">
<match url="([\S]+)(/v-[0-9]+/)([\S]+)" />
<action type="Rewrite" url="{R:1}/{R:3}" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.