Lesson 7 of 9 · 21m
Application Builds: Chunks, Hashes, and Cache Strategy
Production output is an artifact contract — entry chunks, shared chunks, hashed assets, sourcemaps, compression, and cache headers that must line up.
A production frontend deploy is an atomicity problem disguised as a JavaScript problem. HTML references an entry; the entry imports chunks; chunks reference assets. If any layer is cached inconsistently, users get white screens that vanish before support can reproduce them. Understanding the artifact graph is more valuable than memorizing build flags.
What vite build emits
dist/
index.html
assets/
index-B7mQ9x2A.js entry chunk
vendor-Cx91pLaa.js shared dependency chunk
route-settings-Ddk2.js lazy chunk
logo-D81s.png hashed assetThe content hash is a cache key. When content changes, the filename changes, which lets immutable assets live under long cache headers. index.html, however, must not be cached aggressively because it is the pointer to the current artifact generation.
Manual chunks are a scalpel
export default {
build: {
rollupOptions: {
output: {
manualChunks: {
react: ["react", "react-dom"],
charts: ["recharts"],
},
},
},
},
};Use manual chunks when dependency ownership is clear: huge visualization libraries, maps, editors. Do not shard every package. Excess chunks increase request overhead and can duplicate shared code if boundaries are wrong.
Sourcemaps are release infrastructure
export default {
build: { sourcemap: "hidden" },
};hidden emits maps without adding //# sourceMappingURL comments. Upload them to your error tracker, restrict public access, and delete or retain them according to your incident process. A stack trace without symbols is telemetry theater.
Deployment headers matter as much as build config
/index.html Cache-Control: no-cache
/assets/* Cache-Control: public, max-age=31536000, immutableIf HTML is immutable, deploys appear broken. If assets are not immutable, users re-download unchanged JavaScript forever. Neither is a bundler bug, but both get reported as one.
Field notes
- Test the artifact, not only the build:
vite build && vite previewcatches path, base, and asset mistakes. basemust match the public deployment path, especially behind nested reverse proxies.- gzip is table stakes; brotli precompression helps static hosts but does not replace correct cache policy.
- A missing chunk after deploy often means HTML from the new generation references assets the old upload never replaced atomically.
Was this lesson helpful?