gulpbundling-and-minificationasp.net-core-mvcasp.net-bundling

Migrating ASP.NET MVC 5 bundling "versions" to MVC 6


The bundling feature is excluded from MVC 6 and the suggested method is to do bundling using gulp tasks.

Using bundling we used to get a random string at the end of the included css/javascript file url(s). This string was very important because once you changed anything in your css/javascript then a new string would be generated which would force browsers to load the new version(s) of the file(s).

So if you had 3 css files they would be bundled into one and they would look like this:

<link href="/Style/css?v=sGJNctjkEuiEEdR68fh0dDt7bwrHIbu_EfQtgon7oYc1" rel="stylesheet">

How can we achieve the same functionality in MVC 6? I don't know whether gulp can help here or not but I am already using gulp to do minification and bundling.


Solution

  • For beta6 set asp-file-version="true" to retain cache-busting behavior:

    <link rel="stylesheet" href="~/css/site.min.css" asp-file-version="true" />
    

    For beta7, use asp-append-version="true".