I just published a new Nuget package, AspNet.Mvc.AssetVersioning. This package extends the MVC5
@Url Razor helper with a new
VersionedContent method which appends a Base64-encoded SHA256 hash to the end of the URL for cache-busting.
Versioning in ASP.NET Core
In ASP.NET Core, you can version URLs using the
asp-append-version tag helper:
Which will output:
Versioning in ASP.NET MVC 5
Since I have not yet migrated to ASP.NET Core for Keep Track of My Games, I needed the same functionality in order to remove some old libraries that are not available in .NET Core. Now you can achieve the same thing using my package:
This will output the following:
The helper will automatically cache hashes for files for the lifetime of the
HttpContext. So, basically, for the lifetime of the application pool. Restart the site/app pool to refresh the cache, which should happen on any new deployments.
You can simplify the
@using statement usage by adding the namespace to the
/configuration/system.web.webPages.razor/pages/namespaces section in the
Views/web.config file, as outlined in the GitHub repo README.
Hope this helps someone else facing the same issue!