Chapter 15: Building an app
Introduces Luma Books and outlines the static Vanilla Web app that the chapter builds.
After this chapter you will be able to
- Luma Books app architecture. Describe how Luma Books gets its book data, renders screens, saves cart and order data, and uses metadata.
- Smallest useful technology set. Explain why Luma Books selects a small set of technologies before coding instead of using every technique the book presents.
- Single responsibilities for app parts. Describe the distinct jobs assigned to the router, store, page components, and small reusable components.
- HTML project entry point. Describe how /index.html starts the project by linking the manifest, favicon, CSS files, and JavaScript module entry point at /src/app.js.
- Responsibility-based CSS organization. Explain how the four CSS files divide styling responsibilities and why the section favors this arrangement: the files remain readable and modular without unnecessary abstraction, while @layer makes cascade order explicit.
- Route-specific document titles. Explain why the HTML title is only an initial value and how this app keeps titles useful after client-side navigation.
- Coordinated installed-app colors. Explain which theme and background colors must match across the HTML, CSS, and manifest, and why.
- Critical dependency preloads. Explain why this app preloads deeper modules instead of its entry module and when those preloads are justified.
- Deep-route asset paths. Explain why paths in the document head are absolute and why the manifest and service worker instead use scope-relative paths.
- Persistent shell and route outlet. Explain what the application shell renders and what the router replaces when the route changes.
- Route definitions and pages. Describe what an app route declares and how a matched route leads to a page component.
- Route matching fallback. Explain how the app matches routes when URLPattern is or is not available.
- Progressively enhanced link navigation. Explain how link navigation is intercepted without replacing ordinary link behavior, and identify how intercepted navigation reaches page rendering.
- Programmatic navigation consistency. Describe how navigateTo(url) handles navigation initiated by code across browsers.
- Book loading and cache fallback. Trace how the app loads its static book catalog and uses a cached copy when a later fetch fails.
- Catalog card safe rendering. Describe how the book card receives and presents a book, triggers cart changes, and keeps user-controlled text from being parsed as markup.
- Checkout submission across shadow DOM. Explain why the async button cannot submit the outer form directly from its shadow DOM and how it submits through ElementInternals.
- Cart store subscriptions. Trace how a component receives cart state when it subscribes and when the cart later changes.
- Data and rendering separation. Distinguish the cart store’s responsibility from the components’ responsibility.
- Installable app metadata. Explain what the app’s web app manifest defines and how its metadata supports the installation dialog.
- Offline shell and navigation. Trace what the service worker caches and what happens when an installed app navigates without a network connection.
- Smoke Test Purpose. Explain that a smoke test quickly checks whether an application’s most important parts work, rather than testing every edge case.
- App Smoke Test Checks. Describe how this app’s browser-based test uses the app’s modules to check the catalog and confirm that cart quantity survives an IndexedDB reload. Explain that this keeps testing close to the web platform without a full test runner.
- Production route fallback. Explain why a production host must serve /index.html for Luma Books application routes, and how the client-side router uses the requested URL afterward. Describe where the sample deployment configuration must be placed.
- Selective fallback rules. Distinguish requests that should receive a real file from extensionless app paths that should fall back to /index.html, and explain why rewriting every request is harmful.
- Unfingerprinted asset caching. Justify the sample's caching rules for code and images, and contrast them with the rule that would become appropriate for hashed code filenames.
- Transparent Vanilla Web integration. Explain how Luma Books brings techniques from across the book into one modest app, and why that modest scale makes the example useful.
What it builds on
- Data binding techniques (chapter 13) · The book presents several data-binding techniques from which an app can choose.
- State management (chapter 13) · The idea of managing app state.
- Maintainable and modular CSS (chapter 4) · The guidance to keep CSS maintainable and modular.
- Cascade Layers (chapter 4) · The use of cascade layers to make style ordering explicit.
- Viewport definition (chapter 3) · The viewport definition and viewport-fit=cover variant introduced earlier.
- Title and metadata (chapter 11) · Route rendering can update page titles and metadata.
- Theme color (chapter 3) · The theme-color metadata introduced earlier.
- Preloading and execution order (chapter 5) · Module preloading and execution-order behavior.
Section by section
Introduction
Introduces Luma Books and outlines the static Vanilla Web app that the chapter builds.
- Luma Books app architecture: Describe how Luma Books gets its book data, renders screens, saves cart and order data, and uses metadata.
Why it matters: This overview gives you a way to place each part of the bookshop as the chapter builds it.
Key terms: Luma Books, JSON file, Web Components, IndexedDB, metadata
15.1 Planning
The section plans Luma Books around a small set of complementary techniques and clear responsibilities for each part of the app.
- Smallest useful technology set: Explain why Luma Books selects a small set of technologies before coding instead of using every technique the book presents.
Why it matters: Choosing complementary techniques keeps the app from accumulating unnecessary approaches to the same problem. - Single responsibilities for app parts: Describe the distinct jobs assigned to the router, store, page components, and small reusable components.
Why it matters: Clear jobs make it easier to decide where each piece of app behavior belongs.
Key terms: smallest useful set, data-binding techniques, router, store, page components, small reusable components, shared cart state
15.2 Setting up the project
The section establishes the app’s HTML entry point and a small, responsibility-based CSS structure.
- HTML project entry point: Describe how /index.html starts the project by linking the manifest, favicon, CSS files, and JavaScript module entry point at /src/app.js.
Why it matters: This identifies where the app’s resources are brought together. - Responsibility-based CSS organization: Explain how the four CSS files divide styling responsibilities and why the section favors this arrangement: the files remain readable and modular without unnecessary abstraction, while @layer makes cascade order explicit.
Why it matters: This structure makes the app’s styles easier to read without hiding their cascade order.
Key terms: index.html, manifest, favicon, module entry point, theme.css, base.css, layout.css, components.css, @layer
15.2.1 The document metadata
This section explains how the app’s document metadata coordinates with routing, styling, module loading, and installability.
- Encoding and viewport choices: Explain why the character encoding appears first and why this app uses a plain device-width viewport rather than viewport-fit=cover.
Why it matters: These settings reflect how this particular app is laid out, rather than a generic metadata checklist. - Route-specific document titles: Explain why the HTML title is only an initial value and how this app keeps titles useful after client-side navigation.
Why it matters: A changing title helps users distinguish pages in their tabs and browser history. - Coordinated installed-app colors: Explain which theme and background colors must match across the HTML, CSS, and manifest, and why.
Why it matters: Matching these values avoids a mismatched app frame or a splash-screen color flash. - Critical dependency preloads: Explain why this app preloads deeper modules instead of its entry module and when those preloads are justified.
Why it matters: The useful preloads shorten the import-discovery waterfall without redundantly preloading the entry point. - Deep-route asset paths: Explain why paths in the document head are absolute and why the manifest and service worker instead use scope-relative paths.
Why it matters: The path distinction keeps deep links working without sacrificing subfolder installation.
Key terms: character encoding, viewport, width=device-width, initial-scale=1, viewport-fit=cover, <title>, client-side router, renderElement(), document.title, theme-color, --color-primary
15.3 Screens and app architecture
The section maps Luma Books’ six routes to screens and describes a persistent application shell whose outlet displays the current page.
- Route-level screen map: Describe the app’s six route-level screens and distinguish the book-detail and order-confirmation routes, which include an :id parameter.
Why it matters: The route map identifies which screen the app should show at each URL. - Persistent shell and route outlet: Explain what the application shell renders and what the router replaces when the route changes.
Why it matters: This division makes clear what remains stable and what changes between screens.
Key terms: route-level screens, /products/:id, /order/:id, application shell, /src/app-shell.js, route outlet, page components
15.4 Routing and navigation
This section shows how the app connects route definitions to web-component pages while keeping link, programmatic, and optional animated navigation usable across browser capabilities.
- Route definitions and pages: Describe what an app route declares and how a matched route leads to a page component.
Why it matters: This explains how a URL selects a page without loading every page module up front. - Route matching fallback: Explain how the app matches routes when URLPattern is or is not available.
Why it matters: Routes can still be recognized in browsers without URLPattern. - Progressively enhanced link navigation: Explain how link navigation is intercepted without replacing ordinary link behavior, and identify how intercepted navigation reaches page rendering.
Why it matters: Navigation gains app behavior without sacrificing what users expect from links. - Optional view transitions: Explain when the app skips a view transition.
Why it matters: A page change need not depend on animation or override a reduced-motion preference. - Programmatic navigation consistency: Describe how navigateTo(url) handles navigation initiated by code across browsers.
Why it matters: Code-triggered route changes behave consistently instead of reloading the page in one browser.
Key terms: route table, lazy import, custom element name, URLPattern, path-matcher.js, literal segments, :name parameters, Navigation API, history-router.js, real <a href> links
15.5 Loading and persisting data
This section shows how the app loads book data, caches it for failed fetches, and stores local cart and order data in IndexedDB.
- Book loading and cache fallback: Trace how the app loads its static book catalog and uses a cached copy when a later fetch fails.
Why it matters: The app can show previously loaded book data even when a later request fails. - Promise wrapper for IndexedDB: Explain what the local IndexedDB micro-library does and why the app uses it.
Why it matters: The wrapper makes storage code less repetitive while keeping IndexedDB's model visible. - Three local object stores: Describe the purpose of each IndexedDB object store in the app.
Why it matters: The store names show which app data is cached or kept locally.
Key terms: books-api.js, fetch(), AbortSignal, IndexedDB, idb-promises.js, micro-library, IndexedDB requests and transactions, Promises, books, cart
15.6 Web components
This section shows how the app uses web components for its header, catalog, detail screen, and checkout, including safe rendering and form submission across a shadow boundary.
- Header subscription cleanup: Explain how the site header keeps the cart count current and cleans up its subscription when the component disconnects.
Why it matters: A component that subscribes to shared data also needs to release that subscription when it leaves the page. - Catalog card safe rendering: Describe how the book card receives and presents a book, triggers cart changes, and keeps user-controlled text from being parsed as markup.
Why it matters: The card illustrates both component integration and a practical boundary between trusted markup and untrusted text. - Rating and detail composition: Distinguish what the rating and book-details components own from what their callers supply.
Why it matters: These examples show two ways components provide a reusable structure without hard-coding every value or piece of content. - Checkout submission across shadow DOM: Explain why the async button cannot submit the outer form directly from its shadow DOM and how it submits through ElementInternals.
Why it matters: This lets a shadow-DOM submit control participate in ordinary form validation and submission without changing the checkout page’s submit listener.
Key terms: cart store, unsubscribe function, disconnectedCallback(), book object, cart service, <template>, textContent, innerHTML, book-rating, value attribute
15.7 Data flow and reactivity
This section explains how the cart store notifies components of state changes while leaving rendering to the components.
- Cart store subscriptions: Trace how a component receives cart state when it subscribes and when the cart later changes.
Why it matters: Components can render the current cart without waiting for a change and stay updated afterward. - Batched change notifications: Explain why the cart store uses queueMicrotask() before dispatching change events.
Why it matters: Components are notified once for a group of synchronous updates rather than separately for each one. - Data and rendering separation: Distinguish the cart store’s responsibility from the components’ responsibility.
Why it matters: Keeping DOM rendering out of the store makes the boundary between state and UI clear.
Key terms: EventTarget, subscribeCart(), cart store, queueMicrotask(), change events, synchronous updates, store, DOM, components, cart data
15.8 Making the app installable and offline-capable
This section shows how the app uses a web app manifest and a conservatively caching service worker to support installation and offline use.
- Installable app metadata: Explain what the app’s web app manifest defines and how its metadata supports the installation dialog.
Why it matters: The manifest gives compatible browsers the information needed to present the app for installation. - Offline shell and navigation: Trace what the service worker caches and what happens when an installed app navigates without a network connection.
Why it matters: The cached app can remain useful offline rather than immediately showing an offline error page. - Nested-route worker registration: Explain how the app registers its service worker reliably and what happens when service workers are unsupported.
Why it matters: Registration must work from deep links without making service-worker support a requirement for online use.
Key terms: web app manifest, /manifest.webmanifest, installation dialog, service worker, precache, application shell, network-first, IndexedDB, /offline.html, /src/services/pwa.js
15.9 Testing and running
The section explains the app’s browser-based smoke test, what it checks, and where to open the app and test locally.
- Smoke Test Purpose: Explain that a smoke test quickly checks whether an application’s most important parts work, rather than testing every edge case.
Why it matters: It clarifies what a passing smoke test does—and does not—establish. - App Smoke Test Checks: Describe how this app’s browser-based test uses the app’s modules to check the catalog and confirm that cart quantity survives an IndexedDB reload. Explain that this keeps testing close to the web platform without a full test runner.
Why it matters: The test checks both catalog data and whether cart data persists after a reload.
Key terms: smoke test, edge case, browser-based smoke test, catalog, cart quantity, IndexedDB, test runner
15.10 Deployment notes
The section explains how to deploy Luma Books with route fallbacks, correct resource headers and caching, and a GitHub Pages workaround.
- Production route fallback: Explain why a production host must serve /index.html for Luma Books application routes, and how the client-side router uses the requested URL afterward. Describe where the sample deployment configuration must be placed.
Why it matters: A working client-side route still needs the host to deliver the app when someone opens that URL directly. - Selective fallback rules: Distinguish requests that should receive a real file from extensionless app paths that should fall back to /index.html, and explain why rewriting every request is harmful.
Why it matters: A selective fallback keeps missing JavaScript files from masquerading as broken imports or MIME type problems. - Manifest content type: Explain why the deployment serves the web app manifest as application/manifest+json.
Why it matters: A wrong manifest content type can silently prevent installation. - Service worker revalidation: Explain why the service worker uses no-cache and what that directive means here.
Why it matters: Revalidation helps a deployed service worker fix reach users instead of leaving an older worker in control. - Unfingerprinted asset caching: Justify the sample's caching rules for code and images, and contrast them with the rule that would become appropriate for hashed code filenames.
Why it matters: Cache lifetimes must match whether a changed asset gets a new URL. - GitHub Pages route workaround: Describe how the sample makes app routes boot on GitHub Pages and why this is not equivalent to a real rewrite.
Why it matters: An app that appears to load on GitHub Pages may still return a 404 response for its routes.
Key terms: application routes, fallback, rewrite rule, client-side router, /deploy/, real file, file extension, MIME type error, .webmanifest, application/manifest+json
15.11 Closing notes
The closing notes present Luma Books as a small application that brings the book’s Vanilla Web techniques together while keeping each file’s purpose clear.
- Transparent Vanilla Web integration: Explain how Luma Books brings techniques from across the book into one modest app, and why that modest scale makes the example useful.
Why it matters: The app is useful as a final example because its small size lets you see how the pieces fit together.
Key terms: Luma Books, Vanilla Web, framework
15.12 Summary
Concepts explained in this chapter
- fallbackAn alternative implementation or behavior used when a preferred feature or supplied content is unavailable.
- rewrite ruleA rewrite rule is server configuration that maps an incoming request path to a different resource or response without changing the requested URL.
- routingComparing a navigation destination with route definitions to select a view or handler.
- ElementInternalsElementInternals is a browser interface that provides a custom element with access to internal capabilities such as form participation and accessibility semantics.
- form-associated custom elementA form-associated custom element is a custom HTML element that participates in a form's association, disabled-state, reset, and state-restoration behavior.
- application shellAn application shell is the persistent structure and shared interface of an application around content that changes or loads separately.
- Navigation APIA browser API for observing and controlling navigation, including intercepting navigations.
- URLPatternURLPattern is a web-platform API for matching URLs against structured patterns and extracting their components or parameters.
- progressive enhancementProgressive enhancement is an approach that starts with broadly compatible baseline functionality and adds capabilities when supported by the user's device and browser.
- service workerA service worker is a browser-managed background script that can intercept network requests and support offline behavior, caching, and other progressive web application features.
- web app manifestA Web App Manifest is a JSON document that supplies metadata describing a web application, such as its name, icons, colors, and launch URL.
- componentA self-contained software unit designed for use in multiple parts of an application or across applications.
- history.pushState()history.pushState() adds a session-history entry with optional state and URL without loading a new document.
- micro-libraryA small software library providing narrowly scoped functionality.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
