Bundling and Minification in ASP.NET Core MVC

Goal: Bundle and minify static files, forcing browser updates when content changes.

Bundle and Minify

Create bundleconfig.json in the project root:

[
    {
        "outputFileName": "wwwroot/css/site.min.css",
        "inputFiles": [
            "wwwroot/css/site.css"
        ]
    },
    {
        "outputFileName": "wwwroot/js/site.min.js",
        "inputFiles": [
            "wwwroot/js/site.js"
        ],
        "minify": {
            "enabled": true,
            "renameLocals": true
        },
        "sourceMap": false
    }
]

Reference Bundled Files

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
</head>
<body>
    <footer>
        .......
    </footer>

    <script src="~/js/site.min.js" asp-append-version="true"></script>
</body>
</html>

The asp-append-version="true" attribute appends a version hash to the file URL, bypassing browser cache when content changes.