liveBook · Manning

Asp-fallback-href

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

The asp-fallback-href attribute specifies a local stylesheet URL to use when the primary stylesheet source is unavailable.

The asp-fallback-href attribute gives a link tag helper a local stylesheet URL to use when a CDN-hosted stylesheet is unavailable. It works with href and fallback-test attributes that let browser-side code verify whether the CDN stylesheet loaded. section 26.4.2

Bootstrap CDN with a local fallback

In a shared layout, set href to the Bootstrap CDN URL and asp-fallback-href to /lib/bootstrap/css/bootstrap.min.css. Add asp-fallback-test-class="btn", asp-fallback-test-property="display", and asp-fallback-test-value="inline-block". The tag helper emits the CDN link, a test meta element, and JavaScript that checks the CSS property before writing the local fallback link. section 26.4.2

Table 26.6. The built-in tag helper attributes for link elements (view table figure)

Name

Description

asp-href-include

This attribute is used to select files for the href attribute of the output element.

asp-href-exclude

This attribute is used to exclude files from the href attribute of the output element.

asp-append-version

This attribute is used to enable cache busting, as described in the “Understanding Cache Busting” sidebar.

asp-fallback-href

This attribute is used to specify a fallback file if there is a problem with a CDN.

asp-fallback-href-include

This attribute is used to select files that will be used if there is a CDN problem.

asp-fallback-href-exclude

This attribute is used to exclude files from the set that will be used when there is a CDN problem.

asp-fallback-href-test-class

This attribute is used to specify the CSS class that will be used to test the CDN.

asp-fallback-href-test-property

This attribute is used to specify the CSS property that will be used to test the CDN.

asp-fallback-href-test-value

This attribute is used to specify the CSS value that will be used to test the CDN.

Use the link-element attribute table to compare asp-fallback-href with fallback file selection and fallback test attributes. section 26.4.2

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

How deep it goes
Explains layout configuration and generated browser checks, stopping short of broader stylesheet delivery design.
Examples
Uses Bootstrap 5.2.3, the btn class, display:inline-block, and /lib/bootstrap/css/bootstrap.min.css.
What it assumes
Assumes a CDN stylesheet, a matching local file, and a CSS class defined by that stylesheet.
What you can do after
Operate/configure a Bootstrap stylesheet CDN fallback in a shared ASP.NET Core layout.
How it connects
Connects CDN delivery, CSS stylesheets, built-in tag helpers, CSS classes, and JavaScript-based feature detection.

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.