JS Guide
HomeQuestionsSearchResources
Search

Built for developers preparing for JavaScript, React & TypeScript interviews.

ResourcesQuestionsSupport
HomeQuestionsSearchProgress
HomeQuestionsperformance
Prev
performance
junior
bundling

What is minification and bundling, and why are they important?

minification
bundling
webpack
vite
optimization
Quick Answer

Minification removes unnecessary characters (whitespace, comments) from code to reduce file size. Bundling combines multiple files into fewer files to reduce HTTP requests. Both reduce load times - bundlers like webpack, Vite handle this automatically.

Detailed Explanation

Minification:

  • Removes whitespace and comments
  • Shortens variable names
  • Reduces file size significantly
  • No change to functionality

Bundling:

  • Combines multiple files into one/few
  • Reduces HTTP requests
  • Enables code splitting
  • Tree-shaking removes unused code

Modern Bundlers:

  • Webpack: Most configurable
  • Vite: Fast dev, Rollup for prod
  • esbuild: Extremely fast
  • Rollup: Best tree-shaking

Results:

  • 60-80% size reduction common
  • Faster page loads
  • Better compression

Code Examples

Minification example
// Before minification (readable)
function calculateTotal(items) {
  // Calculate the sum of all item prices
  const total = items.reduce((sum, item) => {
    return sum + item.price;
  }, 0);
  
  return total;
}

// After minification (production)
function calculateTotal(t){return t.reduce((t,e)=>t+e.price,0)}

// Typical file size reduction:
// Original: 1.2 MB
// Minified: 450 KB (63% reduction)
// Gzipped:  120 KB (90% reduction)

// Common minification tools:
// - Terser (JavaScript)
// - cssnano (CSS)
// - html-minifier (HTML)

Resources

Vite Build Options

docs

Terser

docs

Related Questions

How does code splitting work and when should you use it?

mid
bundling
Previous
What are the different types of caching for web applications?