Menu

Post image 1
Post image 2
Post image 3
1 / 3
0

How I cut Next.js bundle size by analysing and reducing chunk bloat

DEV Community: webpack·Nayan Kyada·3 days ago
#nVP82LR1
#dev#fullscreen#react#next#import#article
Reading 0:00
15s threshold

Next.js bundle size analysis is one of the highest-ROI performance tasks you can do — it takes an afternoon, and the wins compound across every page. Here is exactly how I ran it on a client e-commerce site and cut first-load JS from 487 kB to 301 kB. Setting up @next /bundle-analyzer Install the package and wire it into next.config.ts . // next.config.ts import type { NextConfig } from ' next ' ; import withBundleAnalyzer from ' @next/bundle-analyzer ' ; const withAnalyzer = withBundleAnalyzer ({ enabled : process . env . ANALYZE === ' true ' , openAnalyzer : true , }); const nextConfig : NextConfig = { // your existing config }; export default withAnalyzer ( nextConfig ); Enter fullscreen mode Exit fullscreen mode Then run: ANALYZE = true next build Enter fullscreen mode Exit fullscreen mode This opens two treemap files in your browser — one for the client bundle, one for the server bundle. The client treemap is the one to fix first because it is what your users download.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More