<script type="text/javascript" src="@Url.ContentVersioned("/Scripts/libs/backbone-min.js")"></script>
Last active
December 21, 2020 11:18
-
-
Save martinnormark/4537250 to your computer and use it in GitHub Desktop.
Adding build number to static file paths for cache busting in ASP.NET MVC
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
public static class UrlHelperExtensions | |
{ | |
private static int _revisionNumber; | |
public static string ContentVersioned(this UrlHelper urlHelper, string contentPath) | |
{ | |
string url = urlHelper.Content(contentPath); | |
int revisionNumber = GetRevisionNumber(); | |
return String.Format("{0}?v={1}", url, revisionNumber); | |
} | |
public static int GetRevisionNumber() | |
{ | |
if (_revisionNumber == 0) | |
{ | |
Version v = Assembly.GetExecutingAssembly().GetName().Version; | |
_revisionNumber = v.Revision; | |
} | |
return _revisionNumber; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment