Chapter 14: Beyond basics
This chapter introduction previews small libraries, performance techniques, offline support, and installability for Vanilla Web apps.
After this chapter you will be able to
- Focused micro-library purpose. Explain that a micro-library is a small tool with a narrow contract that removes repetitive glue code for one task while leaving the underlying web platform understandable.
- Vanilla project dependency boundary. Distinguish a focused micro-library from a small library that takes over the application's architecture. Explain why adopting a tool for one concern need not hand routing, rendering, data flow, or deployment to a larger runtime.
- Single Problem Focus. Explain why a micro-library should solve one clear problem rather than expand into unrelated features.
- Platform Native Integration. Describe how a micro-library should preserve web platform objects and compose with existing integration points, leaving the app recognizable if the library is removed.
- Small JavaScript library APIs. Explain how JavaScript’s language features and built-in platform contracts let micro-libraries expose small APIs without special tooling.
- Dependency fragmentation costs. Explain how several small, overlapping packages can create more maintenance work than one carefully chosen library.
- Architectural drift and coupling. Explain how a minor utility can end up shaping an entire application and recreate framework-like lock-in.
- Platform-first library choice. Justify using micro-libraries to reduce friction rather than replace basic understanding, and preferring a direct, readable browser API when one exists.
- Practical micro-library adoption. Explain why a team should ask practical questions before adding a micro-library: the dependency decision should be easy to explain and should consider architectural size, not just kilobytes.
- Micro-library extraction and shape. Explain why a micro-library is best extracted after a pattern has appeared two or three times in real code, and describe the resulting design: a narrow entry point, explicit inputs and outputs, predictable cleanup, no hidden globals, and few assumptions about the surrounding app.
- Minimal reusable store core. Explain what to extract when small apps repeatedly need the same store-and-render glue, and what the library does not need to include.
- Multiple integration points. Explain why a micro-library should work from an ES module, a custom element, a server-rendered page, or a larger framework without requiring special project-wide tooling.
- Platform-shaped helper APIs. Describe the familiar API shapes recommended for micro-libraries, including explicit inputs and outputs, cleanup functions, and AbortSignal cancellation. Explain why a helper that accepts an AbortSignal and returns cleanup composes with other browser code.
- Adoption focused README content. Describe the practical questions a micro-library README should answer: what the library solves, when not to use it, how to install or import it, and how to use it through a clear API description and complete examples.
- Concrete API and lifecycle documentation. Explain why the README must state exact signatures, input shapes, side effects, return values, and lifecycle rules, explicitly noting cleanup, asynchronous behavior, or feature-detection requirements when applicable.
- Declaration Files and Inference. Explain how a .d.ts file describes a JavaScript library’s public API without implementing it or changing how the library runs. Describe how the store’s generic types let an editor infer the state shape from an initial object.
- Portable ES module packaging. Describe the recommended package shape for a Vanilla-oriented micro-library and where users can import it from.
- Build-free basic adoption. Explain what an npm package should expose and why its basic use should not require a bundler or custom compiler.
- Standards-first library spectrum. Explain that the section’s list includes both strict micro-libraries and lightweight, standards-first layers such as Lit, united by their use of browser primitives rather than a separate application runtime.
- Lit and the custom-element contract. Explain that Lit supplies a base class and rendering system to reduce repetitive component code, while the result remains a standard custom element with familiar HTML and DOM integration.
- Wrec component structure and updates. Describe how a Wrec component is authored and what happens when a reactive property changes.
- Standard custom element interface. Explain how other code uses a component built with Wrec.
- Predeployment HTML generation. Explain that SSG runs a build step before deployment to produce ordinary site files that a static server can host.
- SSG suitability and benefits. Explain when SSG is a strong option and why the location of HTML creation matters more than calling a site static or dynamic.
- Useful HTML in First Response. Explain why SSG can make the initial page useful without waiting for server-side application code or a client-side framework to assemble it.
- Selective Client Side Behavior. Explain how a Vanilla project can combine static content with interactivity in only the parts that need it.
- Generated output selection criteria. Describe how to evaluate an SSG by its output: HTML should work without JavaScript, interactive parts can remain normal HTML and ES modules, and the browser should receive standard files rather than depend on the build tool. Mention practical checks such as metadata control, rebuild support for large content sets, and portable deployment output.
- Lazy loading performance strategy. Explain that lazy loading delays work until it is likely to be needed, moving non-critical work away from the first screen and first interaction.
- Critical work loading boundary. Distinguish work suitable for lazy loading from critical CSS, the main document, core navigation, and the first interaction, which should be ready early.
- Startup and resource priorities. Explain how deferring images, libraries, route modules, and optional widgets can reduce startup cost and let a page render and become interactive sooner. Describe why this lets the browser prioritize visible content, especially on slow devices or unstable networks.
- User-visible loading priorities. Explain what should load immediately and when preloading is appropriate.
- Stable lazy-loading boundaries. Describe which media and features to lazy-load, including the layout precaution for media.
- Visible loading and failure states. Explain why lazy-loaded resources need failure handling and why code loading should remain simple and visible to users.
- Dynamic import loading boundaries. Explain why static imports suit the core path while dynamic imports suit optional features, and describe where a dynamic-import boundary makes sense.
- Browser pipeline performance. Explain that performance depends on small decisions across the browser’s work, including parsing, styling, rendering, JavaScript, networking, storage, and input.
- Vanilla performance tradeoff. Distinguish the overhead Vanilla Web does not require from slow application code it cannot prevent, and state why budgets and measurement remain necessary.
- Performance and user experience. Explain why speed affects whether an app feels reliable and accessible, even when its features work.
- JavaScript cost before usefulness. Explain how requiring substantial JavaScript before the first route becomes useful can obstruct a user’s task, and state the section’s claim about Vanilla Web’s default cost.
- User-centered performance measures. Describe the outcomes the section says to measure: meaningful content appearing, layout stability, first-interaction responsiveness, JavaScript needed before usefulness, and caching benefits on repeat visits.
- Lean initial page delivery. Explain how useful semantic HTML, page-appropriate CSS, and ES module boundaries contribute to the section’s baseline for fast apps.
- Batched layout and rendering. Explain how to avoid repeated layout and redundant renders during a user action.
- Short critical loading path. Explain why resource loading affects performance and describe how to keep CSS and JavaScript on the startup path small.
- Selective resource preloading. Explain when to use preload or modulepreload and why preloading everything defeats their purpose.
- Main-thread performance problems. Explain how JavaScript execution can make an interface feel unresponsive, and identify common execution patterns to investigate.
- Deliberate scheduling tool choices. Distinguish the uses of queueMicrotask(), requestAnimationFrame(), and requestIdleCallback() described here, including the limit on relying on idle callbacks.
- Heavy work in Web Workers. Explain when a Web Worker helps execution performance and why messages between the worker and UI should remain small and explicit.
- Service worker request handling. Describe where a service worker runs and the broad ways it can respond to requests within its scope.
- Service worker role and limits. Explain where a service worker runs relative to controlled pages and the network, and distinguish its available APIs from direct DOM access.
- Optional enhancement and first visit. Justify why the app’s core experience must work without a service worker ready to control it.
- Service worker lifecycle stages. Trace registration, install, and activation, including what can delay a new worker from becoming the active controller.
- App shell caching lifecycle. Describe how a minimal service worker caches the app shell during install and cleans old caches during activate.
- Cache versions and stale files. Explain when to version the cache name and why old resources should be deleted.
- Service worker registration and scope. Describe registering a service worker from a page-loaded module after checking for support, and explain how its location determines its default scope.
- Offline availability choices. Explain that cache design begins by deciding what users need when the network is unavailable, such as the app shell, an offline fallback page, recently viewed content, or static reference data.
- Asset caches and data storage. Distinguish Cache Storage for Request and Response pairs from IndexedDB for domain records, drafts, queues, and local state, and explain why the section keeps them separate.
- Resource-specific cache updates. Describe why cache update decisions differ for hashed files, HTML, and API responses.
- Cache-first serving strategy. Trace how cache-first serving handles a request and explain why it suits versioned static assets.
- Network-first serving strategy. Trace how network-first serving handles a request and explain its use when HTML freshness matters.
- Per-request strategy selection. Explain how one service worker selects a strategy for a request and what happens when no branch handles it.
- Service worker debugging tools. Describe how browser application tools help debug a service worker, including what to inspect and what to log while investigating cache behavior.
- Separate loading and update tests. Explain how to test distinct service worker behaviors during development and how to bypass or unregister the worker when necessary.
- Browser-based app installability. Explain that installability lets a browser present a website as an operating-system app without changing its web code into a native package.
What it builds on
- AbortController and stale requests (chapter 12) · The earlier use of cancellation with AbortController provides context for the AbortSignal example.
- ECMAScript Modules (chapter 5) · ES module imports and exports
- Custom Elements API (chapter 7) · Assumes familiarity with standard custom elements and their registration.
- Using Templates in Web Components (chapter 8) · Assumes familiarity with using templates in Web Components.
- Application architecture (chapter 2) · Introduces SSG as a web application architecture.
- Lazy loading (chapter 5) · Introduces lazy loading of JavaScript modules.
- Preloading and execution order (chapter 5) · Covers module preloading and execution order.
- Web performance (chapter 2) · Earlier discussion of web performance.
Section by section
Introduction
This chapter introduction previews small libraries, performance techniques, offline support, and installability for Vanilla Web apps.
14.1 Micro-libraries
This section explains what micro-libraries contribute to Vanilla projects and how to distinguish a focused helper from a framework-shaped dependency.
- Focused micro-library purpose: Explain that a micro-library is a small tool with a narrow contract that removes repetitive glue code for one task while leaving the underlying web platform understandable.
Why it matters: It helps you recognize when a small dependency simplifies your code without obscuring how the app works. - Vanilla project dependency boundary: Distinguish a focused micro-library from a small library that takes over the application's architecture. Explain why adopting a tool for one concern need not hand routing, rendering, data flow, or deployment to a larger runtime.
Why it matters: It lets you judge a dependency by how much control it assumes, not just by its size.
Key terms: micro-library, narrow contract, primitives, glue code, Vanilla projects, single concern, framework-shaped dependency, larger runtime
14.1.1 Design patterns
This section identifies design traits that keep micro-libraries small, compatible with the web platform, and easy to remove from Vanilla projects.
- Single Problem Focus: Explain why a micro-library should solve one clear problem rather than expand into unrelated features.
Why it matters: A clear boundary helps you judge whether a small dependency is staying small. - Platform Native Integration: Describe how a micro-library should preserve web platform objects and compose with existing integration points, leaving the app recognizable if the library is removed.
Why it matters: Keeping the platform visible makes a library easier to integrate and less costly to remove. - Graceful Feature Fallbacks: Explain how a micro-library should behave when a newer browser feature it uses is unavailable.
Why it matters: Graceful handling lets a library remain useful when a browser lacks a newer feature.
Key terms: micro-library, platform objects, functions, modules, promises, events, standard HTML, CSS, and JavaScript, feature detection, progressive enhancement, fail gracefully
14.1.2 Why JavaScript fits micro-libraries
This section explains why JavaScript supports small, interoperable micro-libraries and warns against extending them by patching native prototypes.
- Small JavaScript library APIs: Explain how JavaScript’s language features and built-in platform contracts let micro-libraries expose small APIs without special tooling.
Why it matters: It explains why a useful library can remain small and work with existing web features. - Native prototype patching risks: Explain why modern interoperable micro-libraries should avoid mutating native prototypes.
Why it matters: Avoiding prototype patches helps libraries coexist predictably.
Key terms: micro-libraries, ES modules, functions and closures, tagged template literals, interoperable contracts, small API surface, native prototypes, prototype patching, Array.prototype, HTMLElement.prototype
14.1.3 Limitations
This subsection explains why a micro-library’s small size does not guarantee that it is a good choice, identifying maintenance, architectural, and documentation costs.
- Dependency fragmentation costs: Explain how several small, overlapping packages can create more maintenance work than one carefully chosen library.
Why it matters: Choosing smaller packages does not necessarily mean less maintenance. - Architectural drift and coupling: Explain how a minor utility can end up shaping an entire application and recreate framework-like lock-in.
Why it matters: A small dependency can have a large architectural impact. - Documentation and abstraction cost: Explain why a tiny API may not be worthwhile if understanding its behavior requires substantial investigation.
Why it matters: Less code is not a gain if the abstraction takes more effort to understand. - Platform-first library choice: Justify using micro-libraries to reduce friction rather than replace basic understanding, and preferring a direct, readable browser API when one exists.
Why it matters: The point of a micro-library is to simplify the work, not to add a dependency where the platform is already clear.
Key terms: dependency fragmentation, micro-libraries, architectural drift, accidental coupling, framework lock-in, documentation, tiny API, abstraction, browser API, platform
14.1.4 Adoption checklist
This subsection frames micro-library adoption as a practical, explainable dependency decision rather than a test of minimalism.
- Practical micro-library adoption: Explain why a team should ask practical questions before adding a micro-library: the dependency decision should be easy to explain and should consider architectural size, not just kilobytes.
Why it matters: A tiny download can still be a significant architectural commitment.
Key terms: micro-library, dependency, architectural terms, kilobytes
14.1.5 Creating a micro-library
The section advises when to extract a micro-library and describes the shape that repeated real-world use helps produce.
- Micro-library extraction and shape: Explain why a micro-library is best extracted after a pattern has appeared two or three times in real code, and describe the resulting design: a narrow entry point, explicit inputs and outputs, predictable cleanup, no hidden globals, and few assumptions about the surrounding app.
Why it matters: Waiting for a recurring pattern gives you a better basis for deciding what the library should contain.
Key terms: micro-library, entry point, input and output types, cleanup semantics, hidden globals
14.1.6 Architecture
This section shows how to extract a small store-and-render micro-library without taking over the rest of an app.
- Minimal reusable store core: Explain what to extract when small apps repeatedly need the same store-and-render glue, and what the library does not need to include.
Why it matters: Keeping the library focused lets an app reuse common glue without adopting an entire framework. - Small library architecture qualities: Describe the architectural qualities the section recommends for a small library and what is sufficient to make this example runnable.
Why it matters: These constraints keep the library understandable and avoid locking an app into it.
Key terms: store-and-render glue, state updates, subscriptions, batching, binding helper, scheduling, side effects, frameworks, rendering layers, README
14.1.7 Integration
This section explains how a micro-library can remain easy to integrate by working in different web contexts and using familiar browser API patterns.
- Multiple integration points: Explain why a micro-library should work from an ES module, a custom element, a server-rendered page, or a larger framework without requiring special project-wide tooling.
Why it matters: An easy-to-integrate helper can fit a project without forcing the project to change around it. - Platform-shaped helper APIs: Describe the familiar API shapes recommended for micro-libraries, including explicit inputs and outputs, cleanup functions, and AbortSignal cancellation. Explain why a helper that accepts an AbortSignal and returns cleanup composes with other browser code.
Why it matters: Familiar API shapes make a helper easier to combine with existing code.
Key terms: micro-library, integration points, browser-layer abstraction, cleanup functions, AbortSignal, cancellation
14.1.8 Documentation
This section explains what a micro-library README must say to help people adopt and safely use the library, including when code assistants use its documentation.
- Adoption focused README content: Describe the practical questions a micro-library README should answer: what the library solves, when not to use it, how to install or import it, and how to use it through a clear API description and complete examples.
Why it matters: A prospective user can decide whether the library fits and get started without guessing. - Concrete API and lifecycle documentation: Explain why the README must state exact signatures, input shapes, side effects, return values, and lifecycle rules, explicitly noting cleanup, asynchronous behavior, or feature-detection requirements when applicable.
Why it matters: Explicit behavior and requirements help readers and code assistants avoid unsafe assumptions.
Key terms: micro-libraries, README, complete examples, API contract, side effects, return values, lifecycle rules, feature-detection requirements
14.1.9 Typing declarations
This section explains how a plain-JavaScript micro-library can provide useful type information without changing its runtime behavior or adding unnecessary complexity.
- Declaration Files and Inference: Explain how a .d.ts file describes a JavaScript library’s public API without implementing it or changing how the library runs. Describe how the store’s generic types let an editor infer the state shape from an initial object.
Why it matters: Readers can offer helpful editor support without rewriting a small library in TypeScript. - Type Information Placement: Distinguish when to put type information in JavaScript with JSDoc and when to supply a separate declaration file. Explain how a package can advertise its declaration and why a micro-library’s types should stay small and faithful to its JavaScript contract.
Why it matters: The choice of where to put types should preserve the simplicity of a micro-library while serving its users.
Key terms: TypeScript declaration file, .d.ts, public API, generic type T, generic type V, JSDoc, declaration files, package.json, JavaScript contract
14.1.10 Packaging
Explains how to package a Vanilla-oriented micro-library for portable use without imposing unnecessary build requirements.
- Portable ES module packaging: Describe the recommended package shape for a Vanilla-oriented micro-library and where users can import it from.
Why it matters: A portable module gives users several ways to adopt the library. - Build-free basic adoption: Explain what an npm package should expose and why its basic use should not require a bundler or custom compiler.
Why it matters: Requiring extra tooling can make a small library harder for everyone to adopt.
Key terms: ES module, named exports, CDN, npm package, ESM entry point, bundler, build step, adoption cost
14.2 Useful micro-libraries today
This section frames community micro-libraries as ways to meet common Vanilla Web needs while building on browser primitives.
- Standards-first library spectrum: Explain that the section’s list includes both strict micro-libraries and lightweight, standards-first layers such as Lit, united by their use of browser primitives rather than a separate application runtime.
Why it matters: This distinction helps you understand why the section groups different kinds of lightweight tools together.
Key terms: micro-libraries, standards-first layers, Lit, browser primitives, application runtime
14.3 Lit for components
Explains how Lit reduces the work of authoring Web Components while preserving their standard custom-element contract, and when that trade-off is useful.
- Lit and the custom-element contract: Explain that Lit supplies a base class and rendering system to reduce repetitive component code, while the result remains a standard custom element with familiar HTML and DOM integration.
Why it matters: You can simplify component authoring without making consumers adopt a different component model. - When Lit is worthwhile: Distinguish the reusable-component case where Lit helps from a small one-off interaction where a simpler approach may suffice.
Why it matters: The amount of repeated component work helps determine whether Lit is worth adding.
Key terms: Lit, custom elements, update cycle, template rendering, DOM events, reusable component layer, raw Custom Elements API, boilerplate, plain custom element, render function
14.4 Wrec for components
This section introduces Wrec as a way to author reactive web components while preserving the standard custom-element interface.
- Wrec component structure and updates: Describe how a Wrec component is authored and what happens when a reactive property changes.
Why it matters: This is how Wrec reduces the work of keeping a component’s display in sync with its properties. - Standard custom element interface: Explain how other code uses a component built with Wrec.
Why it matters: Choosing Wrec for authoring does not require callers to learn a Wrec-specific way to use the element. - Wrec and Lit tradeoff: Distinguish the reasons the section gives for considering Wrec versus choosing Lit.
Why it matters: The section frames the choice around desired component features versus confidence in a more established ecosystem.
Key terms: Wrec class, reactive properties, scoped CSS, HTML template, expressions, standard custom elements, properties, attributes, DOM events, automatic property and attribute synchronization
14.5 Static site generation
This section explains how static site generation fits Vanilla Web and when creating HTML before deployment is a good choice.
- Predeployment HTML generation: Explain that SSG runs a build step before deployment to produce ordinary site files that a static server can host.
Why it matters: The timing of HTML creation is the key distinction this section makes about SSG. - Generated pages and enhancement: Describe why SSG fits Vanilla Web: the browser treats generated HTML as an ordinary document, and JavaScript can enhance the parts needing interaction.
Why it matters: Prebuilt pages can still have interactive features where they are needed. - SSG suitability and benefits: Explain when SSG is a strong option and why the location of HTML creation matters more than calling a site static or dynamic.
Why it matters: This criterion helps you choose SSG for the site you are building rather than relying on a static-versus-dynamic label.
Key terms: Static Site Generation, SSG, build step, static server, Vanilla Web, progressively enhance, static, dynamic
14.5.1 Advantages
This section explains how static site generation delivers useful HTML immediately, simplifies hosting, and lets Vanilla projects add interactivity only where needed.
- Useful HTML in First Response: Explain why SSG can make the initial page useful without waiting for server-side application code or a client-side framework to assemble it.
Why it matters: The first document can be useful before JavaScript runs. - Simpler Static Site Operations: Describe how serving generated files reduces deployment and maintenance complexity.
Why it matters: Serving files can reduce the operational work and failure points of a site. - Selective Client Side Behavior: Explain how a Vanilla project can combine static content with interactivity in only the parts that need it.
Why it matters: You can keep the initial document useful while still supporting interactive features.
Key terms: SSG, meaningful HTML, first response, operational complexity, CDN, server state, runtime dependencies, static generation, client-side behavior, content-first parts
14.5.2 Ideas and tools
This section explains how to choose a static site generator for a Vanilla frontend by judging the files it produces rather than the framework it uses.
- Framework-independent static generation: Explain that SSG does not require a particular framework: a small script can turn content and templates into HTML, while larger sites may use an established generator whose files a Vanilla frontend enhances.
Why it matters: You can choose a build tool without committing your frontend to its framework. - Generated output selection criteria: Describe how to evaluate an SSG by its output: HTML should work without JavaScript, interactive parts can remain normal HTML and ES modules, and the browser should receive standard files rather than depend on the build tool. Mention practical checks such as metadata control, rebuild support for large content sets, and portable deployment output.
Why it matters: Judging the generated files helps preserve a portable, progressively usable Vanilla frontend.
Key terms: SSG, build script, Vanilla frontend, clean HTML, <head> metadata, ES modules, incremental builds, portable, standard files
14.6 Lazy loading
This section defines lazy loading as a performance strategy, identifies native tools for deferring work, and cautions against delaying what users need immediately.
- Lazy loading performance strategy: Explain that lazy loading delays work until it is likely to be needed, moving non-critical work away from the first screen and first interaction.
Why it matters: This principle helps you decide what work can wait without slowing the initial experience. - Native deferral tools: Describe the native tools named here and match them to the kinds of work they defer or keep from blocking rendering.
Why it matters: Choosing a tool depends on whether the deferred work is media, rendering, custom logic, or feature code. - Critical work loading boundary: Distinguish work suitable for lazy loading from critical CSS, the main document, core navigation, and the first interaction, which should be ready early.
Why it matters: Deferring essential work can undermine the initial experience that lazy loading is meant to improve.
Key terms: lazy loading, non-critical work, loading="lazy", decoding="async", content-visibility: auto, IntersectionObserver, dynamic import(), critical CSS, core navigation, first interaction
14.6.1 Advantages
This section explains how lazy loading improves startup speed, prioritizes visible content, and keeps optional features easier to maintain.
- Startup and resource priorities: Explain how deferring images, libraries, route modules, and optional widgets can reduce startup cost and let a page render and become interactive sooner. Describe why this lets the browser prioritize visible content, especially on slow devices or unstable networks.
Why it matters: Deferring optional resources helps people get a usable page sooner, particularly when their device or connection is slow. - Optional feature module boundaries: Explain the maintenance benefit of keeping optional features behind their own module boundaries, with dependencies declared locally rather than added to the global startup path.
Why it matters: Local dependencies make it clearer what an optional feature needs without burdening the app’s startup path.
Key terms: lazy loading, startup cost, first render, interactivity, resource prioritization, module boundaries, dependencies, global startup path
14.6.2 Best practices
This section gives practical rules for lazy loading resources without delaying essential content, shifting the layout, or hiding failures from users.
- User-visible loading priorities: Explain what should load immediately and when preloading is appropriate.
Why it matters: Lazy loading helps only if it does not hold back what users need first. - Stable lazy-loading boundaries: Describe which media and features to lazy-load, including the layout precaution for media.
Why it matters: Clear boundaries defer work without making the visible page jump or complicating when features load. - Visible loading and failure states: Explain why lazy-loaded resources need failure handling and why code loading should remain simple and visible to users.
Why it matters: Deferring a resource should not leave users guessing when it is loading or what to do if it fails.
Key terms: critical CSS, core navigation, preload, below the fold, width and height, stable boundaries, feature modules, lazy import, loading, error, and retry states
14.6.3 Importing dynamic modules
Explains where dynamic imports fit in lazy loading and how preloading can prepare an optional module without executing it at startup.
- Dynamic import loading boundaries: Explain why static imports suit the core path while dynamic imports suit optional features, and describe where a dynamic-import boundary makes sense.
Why it matters: Choosing a boundary that matches when users need a feature keeps optional code off the core loading path. - Preload and execution split: Explain how a preload hint works alongside a later dynamic import when a user is likely to need a module soon.
Why it matters: This lets the browser prepare a likely-needed feature without making it execute at startup.
Key terms: static imports, dynamic imports, core path, optional paths, module boundary, loading boundary, preload hint, dynamic import, import(), startup path
14.7 Best practices for fast web apps
This section frames fast Vanilla Web apps as the result of decisions that respect browser work, without assuming that the absence of framework overhead guarantees performance.
- Browser pipeline performance: Explain that performance depends on small decisions across the browser’s work, including parsing, styling, rendering, JavaScript, networking, storage, and input.
Why it matters: This gives you a broader way to think about where an app may become slow. - Vanilla performance tradeoff: Distinguish the overhead Vanilla Web does not require from slow application code it cannot prevent, and state why budgets and measurement remain necessary.
Why it matters: Avoiding framework overhead is an advantage, not a substitute for checking your app’s performance.
Key terms: browser’s pipeline, layout, painting, compositing, hydration runtime, framework scheduler, virtual tree, main thread, budgets, measurement
14.7.1 Why performance is important
The section explains why web performance matters to users and which outcomes are worth measuring.
- Performance and user experience: Explain why speed affects whether an app feels reliable and accessible, even when its features work.
Why it matters: Performance shapes whether people can comfortably use the app, not just how fast a benchmark runs. - JavaScript cost before usefulness: Explain how requiring substantial JavaScript before the first route becomes useful can obstruct a user’s task, and state the section’s claim about Vanilla Web’s default cost.
Why it matters: Users should not have to wait for the app’s architecture before they can do what they came to do. - User-centered performance measures: Describe the outcomes the section says to measure: meaningful content appearing, layout stability, first-interaction responsiveness, JavaScript needed before usefulness, and caching benefits on repeat visits.
Why it matters: These checks keep performance work focused on whether the page is actually useful to its users.
Key terms: performance, user experience, accessibility, product constraint, first route, JavaScript, Vanilla Web, meaningful content, layout shifts, first interaction
14.7.2 Basic tips
This section gives a practical baseline for making Vanilla Web apps fast through lean delivery, efficient DOM work, safe rendering, and realistic testing.
- Lean initial page delivery: Explain how useful semantic HTML, page-appropriate CSS, and ES module boundaries contribute to the section’s baseline for fast apps.
Why it matters: A fast app starts by delivering useful content without unnecessary page resources or a giant startup script. - Delegated repeated control events: Describe the event-handling choice recommended for repeated controls.
Why it matters: It avoids multiplying identical listeners across repeated controls. - Batched layout and rendering: Explain how to avoid repeated layout and redundant renders during a user action.
Why it matters: Grouping DOM work and rendering avoids repeating work within a single action. - Safe DOM rendering choices: State which DOM rendering choices the section prefers over mixing data into HTML strings.
Why it matters: These choices avoid building rendered content by mixing data with unsafe HTML strings. - Realistic performance testing: Describe where or how to test performance rather than relying only on a development machine.
Why it matters: A fast development machine alone is not a sufficient test of app speed.
Key terms: semantic HTML, modular, ES modules, event delegation, listeners, DOM writes and reads, layout, state, render pass, textContent
14.7.3 Loading resources
The section explains how to keep resource loading from slowing a web app by shortening the critical path and prioritizing only resources needed soon.
- Short critical loading path: Explain why resource loading affects performance and describe how to keep CSS and JavaScript on the startup path small.
Why it matters: Keeping startup resources focused helps the browser deliver the first screen sooner. - Responsive images and asset caching: Describe the section’s recommendations for image sizes and caching fingerprinted assets.
Why it matters: These choices avoid oversized mobile downloads and let suitable assets remain cached. - Selective resource preloading: Explain when to use preload or modulepreload and why preloading everything defeats their purpose.
Why it matters: Selective hints help the browser focus on resources that make an immediate difference.
Key terms: critical path, critical CSS, first paint, type="module", startup imports, responsive images, long-lived caching, fingerprinted assets, preload, modulepreload
14.7.4 Execution performance
This section identifies JavaScript execution patterns that hurt responsiveness and explains when to schedule work or move heavy tasks off the main thread.
- Main-thread performance problems: Explain how JavaScript execution can make an interface feel unresponsive, and identify common execution patterns to investigate.
Why it matters: Spotting work that delays input helps you find why an app feels slow even when it has loaded. - Deliberate scheduling tool choices: Distinguish the uses of queueMicrotask(), requestAnimationFrame(), and requestIdleCallback() described here, including the limit on relying on idle callbacks.
Why it matters: Matching work to the right scheduling opportunity helps keep the interface responsive without making essential behavior depend on idle time. - Heavy work in Web Workers: Explain when a Web Worker helps execution performance and why messages between the worker and UI should remain small and explicit.
Why it matters: Moving heavy computation away from the UI helps only if communication with the worker does not become costly itself.
Key terms: main thread, module evaluation, layout reads, layout writes, pagination, virtualization, queueMicrotask(), requestAnimationFrame(), requestIdleCallback(), Web Worker
14.8 Adding offline support
The section explains why offline support matters and introduces service workers as a way to handle requests when network access is unreliable.
- Offline resilience in real conditions: Explain why offline support makes a website more useful when network access is unreliable or unavailable.
Why it matters: This is the practical reason to add offline support rather than assume a reliable connection. - Service worker request handling: Describe where a service worker runs and the broad ways it can respond to requests within its scope.
Why it matters: Intercepting requests gives the app options when the network cannot provide a response.
Key terms: offline support, service worker, network proxy, Cache Storage, scope
14.8.1 Intro to service workers
Introduces what a service worker can do, why an app must not depend on it immediately, and the main stages of its lifecycle.
- Service worker role and limits: Explain where a service worker runs relative to controlled pages and the network, and distinguish its available APIs from direct DOM access.
Why it matters: This establishes what work a service worker can do without treating it like page JavaScript. - Optional enhancement and first visit: Justify why the app’s core experience must work without a service worker ready to control it.
Why it matters: Users should still get the app’s core experience when worker control is unavailable or not yet ready. - Service worker lifecycle stages: Trace registration, install, and activation, including what can delay a new worker from becoming the active controller.
Why it matters: The stages explain why registering a worker is not the same as having it control a page.
Key terms: service worker, controlled pages, DOM, Cache Storage, fetch, messaging, optional enhancement, first visit, core experience, Registration
14.8.2 Creating a basic service worker
Introduces a basic service worker that caches the app shell during installation, removes old caches during activation, and versions caches to prevent stale files.
- App shell caching lifecycle: Describe how a minimal service worker caches the app shell during install and cleans old caches during activate.
Why it matters: These are the basic cache tasks the section assigns to a service worker. - Cache versions and stale files: Explain when to version the cache name and why old resources should be deleted.
Why it matters: Changing the cache name and removing unused resources helps keep deployed files from being mistaken for current ones.
Key terms: service worker, app shell, install, activate, cache name, activate handler
14.8.3 Registration
This section explains how to register a service worker and why its file location determines the pages it can control by default.
- Service worker registration and scope: Describe registering a service worker from a page-loaded module after checking for support, and explain how its location determines its default scope.
Why it matters: Registration and scope determine which pages the service worker can affect.
Key terms: service worker, register, support, scope
14.8.4 Cache design patterns
This section shows how to choose what remains available offline, where to store it, and how long different cached resources should remain valid.
- Offline availability choices: Explain that cache design begins by deciding what users need when the network is unavailable, such as the app shell, an offline fallback page, recently viewed content, or static reference data.
Why it matters: Starting with offline needs helps you choose useful resources rather than caching indiscriminately. - Asset caches and data storage: Distinguish Cache Storage for Request and Response pairs from IndexedDB for domain records, drafts, queues, and local state, and explain why the section keeps them separate.
Why it matters: Choosing storage by data type makes offline behavior easier to reason about and debug. - Resource-specific cache updates: Describe why cache update decisions differ for hashed files, HTML, and API responses.
Why it matters: Different resources have different freshness needs, so one update rule will not suit them all.
Key terms: app shell, offline fallback page, Cache Storage, Request and Response pairs, IndexedDB, domain records, hashed filenames, HTML, API responses
14.8.5 Serve design patterns
This section explains how a service worker chooses a response strategy for each fetch request and why its choices should be conservative.
- Cache-first serving strategy: Trace how cache-first serving handles a request and explain why it suits versioned static assets.
Why it matters: This helps you explain why some assets can be served from the cache without first contacting the network. - Network-first serving strategy: Trace how network-first serving handles a request and explain its use when HTML freshness matters.
Why it matters: This distinguishes a freshness-oriented response from one that favors a cached asset. - Per-request strategy selection: Explain how one service worker selects a strategy for a request and what happens when no branch handles it.
Why it matters: A clear default keeps the worker from taking over requests it was not designed to serve. - Other strategies and worker risk: Distinguish the other serving strategies named here and explain why service worker choices should be conservative.
Why it matters: Serving choices affect both the suitability of responses and how long a mistake can affect users.
Key terms: fetch event, cache-first, versioned static assets, fetch API, network-first, offline.html, HTML, fetch handler, event.respondWith(), normal network request
14.8.6 Debugging
This section shows how to inspect and test service workers during development so an app’s offline behavior matches what it promises users.
- Service worker debugging tools: Describe how browser application tools help debug a service worker, including what to inspect and what to log while investigating cache behavior.
Why it matters: Inspection and logging make service worker behavior easier to diagnose. - Separate loading and update tests: Explain how to test distinct service worker behaviors during development and how to bypass or unregister the worker when necessary.
Why it matters: Testing distinct states helps reveal failures that a single successful load can hide. - Reliable offline promises: Explain why offline support should be treated as promises to users rather than a single feature checkbox.
Why it matters: Users should be able to rely on the offline behavior an app offers.
Key terms: application tools, Application panel, Cache Storage, strategy decisions, first load, second load, offline load, update behavior, hard reload, browser-tab mode
14.9 Make your web app installable
This section explains what browser installability gives a web app and identifies the page metadata needed to begin making it installable.
- Browser-based app installability: Explain that installability lets a browser present a website as an operating-system app without changing its web code into a native package.
Why it matters: Installability changes how users can access a web app without requiring you to ship a native package. - Initial installability metadata: State which page metadata the section identifies as the initial mandatory part of making a web app installable.
Why it matters: These metadata elements are the starting point the section identifies for making an app installable.
Key terms: installability, standalone window, web APIs, Web App Manifest, icons, theme colors, page metadata
14.10 Summary
Where this is used later
- Web components (chapter 15) · Informs the choice of how to build components for the app.
- Setting up the project (chapter 15) · Informs the choice of project build setup.
- Deployment notes (chapter 15) · Supports evaluating whether generated files can be deployed portably.
- Data flow and reactivity (chapter 15) · Informs how an app handles multiple state changes and rendering.
- Testing and running (chapter 15) · Informs testing choices when running the finished app.
- The document metadata (chapter 15) · The need to budget resource-loading hints.
- Making the app installable and offline-capable (chapter 15) · Motivates making the app offline-capable.
Concepts explained in this chapter
- micro-libraryA small software library providing narrowly scoped functionality.
- lazy initializationA technique that defers loading or initialization until content or functionality is needed.
- ECMAScript moduleAn ECMAScript module is a separately scoped JavaScript module with explicit import and export bindings.
- prerenderingStatic site generation is the process of producing deployable HTML files from templates and content before those files are served to users.
- 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.
- Custom ElementsA developer-defined HTML element registered through the browser's custom element APIs with custom behavior and lifecycle callbacks.
- application shellAn application shell is the persistent structure and shared interface of an application around content that changes or loads separately.
- feature detectionFeature detection is a technique for determining at runtime whether a browser or environment supports a particular capability.
- 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.
- Cache Storage APIThe Cache Storage API is a browser API for storing and retrieving request–response pairs, commonly to support offline use and control of network responses.
- event delegationAn event-handling technique that registers a listener on an ancestor and identifies relevant descendant interactions from the event.
- semantic markupThe practice of using HTML elements according to their meaning to represent a document's content and structure.
- performancePerformance is the speed, responsiveness, and resource efficiency of a software system during operation.
- apiAn API surface is the set of interfaces and operations that software exposes for external use.
- contractA specification of an API's operations, inputs, outputs, and behavioral requirements.
- HTML template elementThe HTML <template> element holds inert markup that can later be cloned and inserted into a document or shadow DOM.
- textContenttextContent is a DOM node property that gets or sets the plain text content of a node and its descendants without parsing markup.
- metadataMetadata is information that defines settings and descriptive properties for a website or web application without changing the document contents displayed in the viewport.
- 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.
- web platformThe collection of browser-provided standards and technologies, including HTML, CSS, and JavaScript, that support web application development.
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.
