liveBook · Manning

Fallback

As explained in Vanilla Web

An alternative implementation or behavior used when a preferred feature or supplied content is unavailable.

A fallback keeps a useful path available when a preferred browser feature, component contribution, or server resource is unavailable. Start with the behavior users need, then add the preferred experience where it works. A fallback need not reproduce every feature; it must preserve the part your application relies on. section 3.8.2 section 10.4.2

Choose the fallback at the boundary where something may be missing:

  • Browser capability: check for an API before using it. Offer another usable behavior when support, permissions, or required user gestures are absent. Check compatibility data rather than assuming that a newly available feature works for every visitor. section 3.8.2 section 2.2.1
  • Component content: put a meaningful default inside a slot. It appears only when no matching content is supplied; supplied content replaces it. Use slots for optional customization, not information required for the component to function. section 8.4.1 section 8.8
  • Routing implementation: use URLPattern when available and a smaller matcher otherwise. If the alternative supports only literal path segments and named parameters, keep route definitions within that shared syntax. section 10.4.2
  • Navigation: use the Navigation API where available. With the History API fallback, change the URL and render from the new location yourself; pushState() does not trigger popstate. section 11.2
  • Deployment: serve real files first, then return index.html for application paths with no file extension. Rewriting every request can turn a missing JavaScript file into an HTML response and a misleading MIME type error. section 15.10

A default action in a component

An optional action slot can contain a disabled “Out of stock” button. If a consumer supplies an “Add to Cart” button for that slot, the default disappears. The component remains understandable without a supplied action, while the consumer controls the enhanced case. section 8.4.2 section 8.4.1

Fallbacks can form a progression rather than a single substitute. For a 3D product view, use the native model element where available, a model-viewer component elsewhere, and an AR Quick Look link as a minimal iOS or iPadOS option. Keep each path tied to an actual requirement, and test the less capable path as deliberately as the preferred one. section 3.6.3 section 3.9

How Vanilla Web covers it

How deep it goes
Works through slot defaults, limited route matching, navigation behavior, and server rewrites without requiring alternatives to duplicate every preferred feature.
Examples
Uses an out-of-stock slot default, a regex route matcher, and an index.html server rewrite for application paths.
What it assumes
Assumes familiarity with HTML and JavaScript while showing how to check API availability and supply defaults in slots.
What you can do after
Build it from scratch by defining a smaller supported behavior, checking availability, and preserving usable content or navigation.
How it connects
Connects progressive enhancement and feature detection to slots, URLPattern, the History API, and client-side routing.

Also explained in

Compare how 24 books explain fallback →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.