liveBook · Manning

Minification

As explained in Pro ASP.NET Core 7, Tenth Edition

Minification is the transformation of source code that reduces its size by removing unnecessary whitespace and shortening names while preserving behavior.

Minification makes JavaScript files smaller by removing whitespace and shortening function and variable names. Smaller files use less bandwidth and reach the client faster, but names such as `x1` make debugging harder. Source maps link minified code to developer-readable source in the browser’s developer tools. section 26.4.1

A `.min.js` filename denotes a minified file. In an ASP.NET Core Razor layout, `asp-src-include` selects files; it does not minify them. Narrow the pattern rather than including every JavaScript file in a package, which may load both minified and unminified versions or multiple feature variants. section 26.4.1

Listing 26.12 Excluding files in the _SimpleLayout.cshtml file in the Views/Shared folder
<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href="/lib/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <script asp-src-include="/lib/jquery/**/*.min.js" 
         asp-src-exclude="**.slim.**">
    </script>
</head>
<body>    
    <div class="m-2">
        @RenderBody()
    </div>
</body>
</html>

The layout includes minified jQuery files and excludes the slim variant, leaving the full minified file. section 26.4.1

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Defines the transformation and its debugging cost, then shows file selection rather than a minification build process.
Examples
Shows jQuery `.min.js` variants selected with `asp-src-include` and narrowed with `asp-src-exclude`.
What you can do after
Apply it via ASP.NET Core script tag helpers to select an existing minified file and avoid unwanted variants.
How it connects
Connects minification to source maps, browser debugging, globbing patterns, and script tag helpers.

Also explained in

Compare how 2 books explain minification →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.