EasyBundle Optimization📖 Theory Question

What is vendor chunk splitting and why is it important for caching?

💡

Hint

Separate third-party code (React, lodash) from app code — vendors change rarely so their chunk stays cached across deploys

Full Answer

Vendor chunk splitting separates third-party dependencies (React, ReactDOM, lodash, etc.) from your application code into a dedicated chunk.

Why it matters for caching:

  • Your application code changes on every deploy; vendor libraries change rarely.
  • Without splitting, a single JS file changes on every deploy — users must re-download React with every code push.
  • With splitting, the vendor chunk URL (content-hashed) stays the same across deploys — it's served from the browser cache immediately.
// vite.config.ts
build: {
  rollupOptions: {
    output: {
      manualChunks: {
        'vendor-react': ['react', 'react-dom'],
        'vendor-router': ['react-router-dom'],
        'vendor-query': ['@tanstack/react-query'],
      }
    }
  }
}

Result: users who visited before only need to download the small app chunk on the next deploy, not the large vendor chunk again.

More Bundle Optimization Questions

EasyWhat is tree shaking and what conditions must be met for it to work?EasyWhat is code splitting and how does dynamic import() enable it?EasyHow do you analyze and diagnose large bundle sizes?MediumWhat is the module/nomodule pattern for differential serving?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint