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.
