Neither is in ECMAScript; both are V8 and embedder (Chrome, Node.js) optimizations that skip repeated startup work.
Code caching skips compiling. After V8 compiles a script to bytecode, it can serialize the compiled functions into a blob. On a later load of the same script, V8 deserializes that blob instead of parsing and compiling again. The cache is checked first: a different V8 version, different flags or a source mismatch makes V8 reject it and compile normally.
In Chrome, per the V8 team's guidance: the first load just compiles (cold run); the second compiles again and stores a cache alongside the HTTP cache entry (warm); the third and later loads use it (hot). Since Chrome 66, the cache is created after the script's top-level code runs, so it includes every function compiled by then. Scripts under 1 KiB and inline scripts aren't cached, and the cache is keyed by URL, so changing a query string starts over. Scripts a service worker caches during its install event get a full cache immediately.
Startup snapshots skip executing. V8 builds each new context from a snapshot of a heap where built-ins and the global object are already set up, instead of running all that initialization. A custom snapshot goes further: run your app's setup once, serialize the resulting heap, and start later processes from it. The V8 team's 2015 post measured context creation dropping from 40 ms to under 2 ms on desktop.
Node.js exposes both:
vm.ScriptcachedDataandcreateCachedData()for code caches you manage yourself.- The module compile cache (
module.enableCompileCache()orNODE_COMPILE_CACHE), which stores code caches on disk for CommonJS, ESM and TypeScript modules. --build-snapshot/--snapshot-bloband thev8.startupSnapshotAPI for custom snapshots.- Single executable applications, which can embed a code cache (
useCodeCache) or a snapshot (useSnapshot).