Vendor and Library Splitting
What you'll learn: How to separate third-party dependencies into their own bundles to maximize browser caching efficiency.
The Core Concept
When your application imports libraries like React, Lodash, or UI frameworks, those files change much less frequently than your own application code. Vendor and library splitting means instructing your bundler to create separate chunks for third-party dependencies, keeping them isolated from your constantly evolving application code.
Think of it like packing for a trip: your toiletries (vendor code) stay the same for years, but your clothing choices (app code) change with every trip. It makes sense to keep them in separate bags so you don't have to repack everything when you just want to swap a shirt.
Why This Matters
When you rebuild your application, only your code changes—not React or other libraries. If everything is bundled together, users must re-download the entire bundle on each deployment. With vendor splitting, users keep the cached vendor bundle and only download your updated application code.
This dramatically reduces bandwidth usage and speeds up repeat visits.
How Bundlers Handle It
Modern bundlers can automatically detect node_modules imports and split them:
// vite.config.js
export default {
build: {
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom']
}
}
}
}
}
Your build generates files like vendor.abc123.js (third-party libraries) and app.xyz789.js (your code). The vendor hash only changes when you upgrade dependencies.
Key Takeaway: Vendor and library splitting separates stable third-party code from frequently-changing application code, enabling long-term browser caching and faster subsequent page loads.