Skip to content

Measuring Impact

Measuring the actual impact of tree shaking and code splitting helps you track progress and identify further optimization opportunities.

Terminal window
# Webpack Bundle Analyzer
npm install --save-dev webpack-bundle-analyzer
# Vite Bundle Visualizer
npm install --save-dev rollup-plugin-visualizer
# Source Map Explorer
npm install --save-dev source-map-explorer
webpack.config.js
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
module.exports = {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: 'bundle-report.html',
openAnalyzer: false
})
]
};
// Using webpack's performance hints
module.exports = {
performance: {
maxAssetSize: 244000, // 244KB
maxEntrypointSize: 400000, // 400KB
hints: 'warning'
}
};
// Programmatic check
console.log(`Initial bundle: ${bundleSize / 1024}KB`);
console.log(`Lazy loaded chunk: ${chunkSize / 1024}KB`);
// Before optimization: 200KB total
// After optimization: 50KB initial + 50KB lazy = 75% reduction 🚀
MetricBeforeAfterImprovement
Initial bundle200KB50KB75%
Parse time800ms200ms75%
Time to Interactive3.2s1.5s53%
  • Use webpack-bundle-analyzer or rollup-plugin-visualizer
  • Track initial vs lazy chunks separately
  • Monitor Time to Interactive improvements
  • Aim for initial bundle < 100KB (compressed)