Created
May 22, 2017 12:52
-
-
Save jovaneyck/e23f80b396d376c7bb6a939c0854744a to your computer and use it in GitHub Desktop.
ASP.NET MVC Bundle cache bust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static class BundleExtensions | |
{ | |
public static Bundle WithLastModifiedToken(this Bundle sb) | |
{ | |
sb.Transforms.Add(new LastModifiedBundleTransform()); | |
return sb; | |
} | |
public class LastModifiedBundleTransform : IBundleTransform | |
{ | |
public void Process(BundleContext context, BundleResponse response) | |
{ | |
foreach (var file in response.Files) | |
{ | |
var lastWrite = File.GetLastWriteTime(HostingEnvironment.MapPath(file.IncludedVirtualPath)).Ticks.ToString(); | |
file.IncludedVirtualPath = string.Concat(file.IncludedVirtualPath, "?v=", lastWrite); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment