liveBook · Manning

CSS tag helper

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

LinkTagHelper is an ASP.NET Core tag helper that processes link elements and resolves stylesheet sources from local files or content delivery networks.

ASP.NET Core’s LinkTagHelper processes link elements in views, managing stylesheet inclusion from local files or content delivery networks. It turns attributes on a layout link into generated stylesheet links and fallback behavior, so small selection mistakes can produce duplicate or unwanted CSS. section 26.4 section 26.4.2

Configure stylesheet selection, caching, and CDN fallback with these attributes:

  • Use asp-href-include to select local files with globbing patterns, and asp-href-exclude to remove unwanted matches such as source maps, subsets, or alternate versions. section 26.4.2
  • Use asp-fallback-test-class, asp-fallback-test-property, and asp-fallback-test-value to test whether the CDN stylesheet actually loaded before inserting the local fallback. section 26.4.2

Select Bootstrap locally, then fall back from a CDN

A layout can select only minified Bootstrap CSS while excluding reboot, grid, utilities, and RTL variants: <link asp-href-include="/lib/bootstrap/css/*.min.css" asp-href-exclude="**/*-reboot*,**/*-grid*,**/*-utilities*, **/*.rtl.*" rel="stylesheet" />. Alternatively, reference the CDNJS Bootstrap 5.2.3 stylesheet and specify /lib/bootstrap/css/bootstrap.min.css as the fallback, testing the btn class for display:inline-block.

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

How deep it goes
Explains glob selection and CDN fallback through layout listings and generated fallback markup, but stops short of implementation internals.
Examples
Uses Bootstrap CSS files, glob patterns, a CDNJS URL, fallback markup, and the btn class as a load test.
What it assumes
Uses ASP.NET Core views, layout files, HTML link elements, and local wwwroot files while teaching the tag helper attributes.
What you can do after
Operate/configure LinkTagHelper to select stylesheet files and provide a tested local fallback for CDN delivery.
How it connects
Connects link elements with tag helpers, globbing, cache busting, content delivery networks, and stylesheet load testing.

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.