The browser exposes hundreds of global APIs and remembering which object is the entry point for a given task is half the battle. This quick reference groups the Web APIs you reach for most — networking, storage, DOM, observers, workers, media, and device — with the global name, its purpose, and a usage note.
How it works
Each entry names a browser global (a constructor like IntersectionObserver, a
namespace like navigator.geolocation, or a function like fetch) and places it
in a category:
- Networking —
fetch,WebSocket,EventSource,XMLHttpRequest. - Storage —
localStorage,sessionStorage,indexedDB,caches,Cookie Store. - DOM & events —
document,CustomEvent,MutationObserver. - Observers —
IntersectionObserver,ResizeObserver,PerformanceObserver. - Workers —
Worker,SharedWorker,ServiceWorker. - Media & graphics — Canvas, WebGL, Web Audio,
getUserMedia. - Device & misc — Geolocation, Clipboard, Notifications, Web Crypto.
Choosing the right API for common tasks
HTTP requests
Prefer fetch for all new code. It returns a Promise, supports async/await,
accepts AbortController for cancellation, and has a clean Request/Response
model with streaming support. Use XMLHttpRequest only for legacy code or when
you specifically need upload progress events (the Fetch API’s ReadableStream
can track download progress but XHR’s upload.onprogress is still easier for
upload tracking).
Client-side data persistence
- Small flags and preferences (under a few KB of strings):
localStorage - Per-tab session state that should clear on close:
sessionStorage - Structured data, offline caches, binary blobs, large datasets:
indexedDB - Offline asset caching for PWAs:
caches(Cache Storage, used via Service Worker)
The localStorage 5 MB limit bites more often than developers expect. If you are
storing JSON arrays that grow over time, switch to IndexedDB before you hit it.
Observing DOM changes without scroll listeners
Scroll and resize event listeners run on every event, which causes layout thrashing if they read layout properties. The Observer APIs batch and defer notifications:
| Task | API to use |
|---|---|
| Lazy-load images when in view | IntersectionObserver |
| Respond to element size changes | ResizeObserver |
| Watch DOM tree for additions/removals | MutationObserver |
| Measure rendering performance | PerformanceObserver |
Off-main-thread processing
A Worker runs JavaScript on a background thread and communicates via
postMessage. Use it for anything CPU-heavy — parsing large JSON, image
manipulation, WebAssembly execution — so the UI does not freeze. SharedWorker
lets multiple tabs or windows share one worker instance, useful for coordinating
state across tabs. ServiceWorker is a network proxy layer for PWA caching and
offline support.
The secure-context requirement
Many APIs only work on HTTPS or localhost. Attempting to use them on plain HTTP
silently fails or throws. APIs that require a secure context include:
navigator.geolocationnavigator.clipboard(Clipboard API)crypto.subtle(Web Crypto)navigator.mediaDevices.getUserMediaServiceWorkerRegistrationNotification.requestPermission
During local development, localhost counts as a secure context, so these APIs
work there. On any HTTP deployment they will not.
Prefer asynchronous, non-blocking patterns
The main thread controls rendering. Any synchronous, long-running operation on the main thread will freeze the page. Prefer:
fetch(async) overXMLHttpRequestwith synchronous modeIntersectionObserverover scroll event listeners withgetBoundingClientRectResizeObserverover window resize listeners- A
Workerfor any computation that would take more than a few milliseconds