liveBook · Manning

Chapter 12: Working with data

What you will learn in chapter 12 of Vanilla Web

The chapter introduces working with data in Vanilla Web by contrasting framework-packaged data features with solutions assembled from browser primitives.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The chapter introduces working with data in Vanilla Web by contrasting framework-packaged data features with solutions assembled from browser primitives.

Key terms: Vanilla Web, browser primitives, data-related concerns

12.1 Working with HTTP

Introduces Fetch as the browser’s standard HTTP interface and explains when its promise resolves relative to reading the response body.

Key terms: Fetch API, Promise-based interface, request, response, fetch() promise, response headers, json(), text(), blob(), response body

12.1.1 Basic usage

This section introduces the basic Fetch API workflow for JSON requests and explains two response-handling pitfalls.

Key terms: Fetch API, request URL, request settings, Promise, Response, response body, fetch(), response.ok, response.status, TypeError

12.1.2 Sending data

This section explains how to choose an HTTP method and send JSON or FormData in a fetch() request.

Key terms: fetch(), method, GET, POST, PUT, PATCH, JSON, request body, content type, FormData

12.1.3 Credentials and cookies

This section explains when fetch() sends credentials and what a server must allow for credentialed cross-origin requests.

Key terms: fetch(), credentials, same-origin, include, omit, CORS headers, Access-Control-Allow-Origin, Access-Control-Allow-Credentials

12.1.4 Headers and response parsing

Explains how to choose a Fetch response-body reader, handle the newer bytes() method, and clone a response when its body needs two consumers.

Key terms: response body, response.json(), bytes(), Baseline Newly available, arrayBuffer(), feature-detect, consumed, clone the response, service workers

12.1.5 AbortController and stale requests

This section explains how to cancel stale HTTP requests and use timeouts or multiple cancellation conditions.

Key terms: AbortController, abort(), stale requests, debouncing, AbortSignal.timeout(), TimeoutError, AbortError, setTimeout(), AbortSignal.any()

12.1.6 Request lifecycle

This section treats HTTP requests as explicit UI lifecycles and explains how state, optimistic updates, retries, and cancellation affect what users see.

Key terms: request lifecycle, initial state, loading state, ready state, empty state, error state, previous data, loading, stale data, state

12.1.7 Streaming responses

Explains how to read fetch responses incrementally, including how to handle text chunks and newline-delimited JSON.

Key terms: fetch(), Response body, ReadableStream, TextDecoderStream, newline-delimited JSON (NDJSON), network chunks, buffer, response.json(), response.text(), clone

12.1.8 Uploads, downloads, and progress

Explains when download progress can be estimated from a streamed response and why precise upload progress may require an API other than fetch().

Key terms: Content-Length, streaming, indeterminate progress indicator, fetch(), XMLHttpRequest, upload progress events, ReadableStream, duplex: "half", Baseline

12.2 Working with WebSockets

This section explains when to use WebSockets, what a minimal client must handle, and how WebSockets compare with other real-time communication options.

Key terms: WebSockets, persistent, bidirectional connection, request/response model, open, message, error, close, connection lifecycle handling, cleanup, Server-Sent Events (SSE)

12.3 Remote data and local caches

Explains how to avoid unnecessary remote requests while keeping cached data fresh and choosing an appropriate cache.

Key terms: in memory cache, Promise, in-flight request, signal, freshness, invalidation, page session, timestamps, HTTP caching headers, browser cache

12.4 Data persistence

Introduces browser data persistence as a choice among storage mechanisms suited to different kinds of data.

Key terms: data persistence, storage mechanisms, shape of the data

12.4.1 Where browser storage lives

Explains where browser-stored data is scoped, why it may not be shared or retained, and how to design around those limits.

Key terms: security context, bucket, origin, storage bucket, partitioning, local data, synchronize, export, storage pressure, prefix

12.4.2 Choosing a storage API

This section gives practical rules for choosing browser storage based on the kind of data, while distinguishing cookies and deprecated storage APIs from current options.

Key terms: Web Storage, IndexedDB, Cache Storage, file system, OPFS, Cookies, HTTP state, session coordination, Application Cache (AppCache), WebSQL

12.4.3 Quotas and persistence

This section explains browser storage quotas, eviction and persistence, how to inspect storage status, and the limits of client-side storage.

Key terms: quota, origin, IndexedDB, Cache Storage, best effort, persistent storage, storage pressure, evict, Storage API, navigator.storage.estimate()

12.4.4 Web Storage

This section explains when Web Storage is appropriate, how its values and lifetimes work, and how storage changes can be observed across tabs.

Key terms: Web Storage, IndexedDB, synchronous, localStorage, sessionStorage, string keys, string values, serialize, browsing session, storage event

12.4.5 IndexedDB

This section explains when IndexedDB is appropriate, how it organizes and versions application data, and what to expect from its API.

Key terms: IndexedDB, structured data, NoSQL database, object stores, key, keyPath, auto-incrementing key generator, indexes, version, upgrade step

12.4.6 Cache Storage

This section explains when Cache Storage fits network-shaped data and why cached responses need an explicit update strategy.

Key terms: Cache Storage, Request, Response, IndexedDB, app shell, offline page, API responses, update strategy, versioned cache names, hashed filenames

12.4.7 File systems

Distinguishes user-owned files from origin-private storage and explains when and how browser apps can access each.

Key terms: File System Access API, user-document storage, permission, showSaveFilePicker(), showOpenFilePicker(), secure context, user gesture, SecurityError, progressive enhancement, Origin Private File System

12.4.8 Debugging and maintenance

This section shows how to inspect browser storage during development and maintain it responsibly in production.

Key terms: DevTools, localStorage, IndexedDB, Cache Storage, origin storage usage, temporary data, quota errors, recovery path, export, user-generated content

12.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 11: Building a router Chapter 13: Data binding and reactivity →

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.