Next.js: `granularChunks` increase page size

Created on 7 Jan 2020  ยท  9Comments  ยท  Source: vercel/next.js

Bug report

Describe the bug

Next version: 9.1.7
I enabled granularChunks in next.config.js

experimental: {
  granularChunks: true,
},

The pages sizes are went up drastically:

Before:

Page                    Size
โ”Œ ฮป /                   1.04 kB
โ”œ   /_app               21 kB
โ”œ ฮป /category/[id]      9.66 kB
โ”œ ฮป /product/[id]       2.41 kB
โ”” ฮป /search             8.66 kB
+ shared by all         194 kB
  โ”œ chunks/commons.js   189 kB
  โ”œ runtime/main.js     4.85 kB
  โ”” runtime/webpack.js  746 B

After:

Page                     Size
โ”Œ ฮป /                    121 kB
โ”œ   /_app                137 kB
โ”œ ฮป /category/[id]       135 kB
โ”œ ฮป /product/[id]        126 kB
โ”” ฮป /search              133 kB
+ shared by all          69.3 kB
  โ”œ chunks/commons.js    22.5 kB
  โ”œ chunks/framework.js  40.8 kB
  โ”œ runtime/main.js      5.23 kB
  โ”” runtime/webpack.js   746 B

System information

  • OS: Windows 10
  • Version of Next.js: 9.1.7

Most helpful comment

Tested on 9.1.8-canary.8:

Page                                                    Size     First Load
โ”Œ ฮป /                                                   818 B        219 kB
โ”œ   /_app                                               22.5 kB      205 kB
โ”œ ฮป /category/[id]                                      3.6 kB       234 kB
โ”œ ฮป /product/[id]                                       3.04 kB      225 kB
โ”” ฮป /search                                             1.12 kB      231 kB
+ shared by all                                         205 kB
  โ”œ static/_buildManifest.js                            305 B
  โ”œ chunks/122263ca4811193d0a92081d2427d6b42500484c.js  114 kB
  โ”œ chunks/commons.js                                   22.4 kB
  โ”œ chunks/framework.js                                 40.8 kB
  โ”œ runtime/main.js                                     4.55 kB
  โ”œ runtime/webpack.js                                  746 B
  โ”” static\<buildId>\pages\_app.js                      22.5 kB

Thanks for the update much easier to understand now!

All 9 comments

The page sizes have not increased โ€” do note that the "shared by all" chunk is now much smaller. These sizes do not reflect individual size, but all of the dependencies which may be shared by some others.

Edit: After I checked the generated files the file size is not matching at all I think it is a different issue.

Maybe I do not understand correctly but after the user visits al the pages he needs to download all the chunks:

1.04 kB
21 kB
9.66 kB
2.41 kB
8.66 kB
194 kB
189 kB
4.85 kB
746 B
======
419.73600 kb



121 kB
137 kB
135 kB
126 kB
133 kB
69.3 kB
22.5 kB
40.8 kB
5.23 kB
746 B
======
659.34600 kb

The 2nd scenario is 30% bigger.


And just visiting only 1 page (main page example:

1.04 kB + 21 kb + 189 kb + 4.89 kb + 746 b = 216.67600 kb
vs
121 kb + 137 kb + 22.5 kb + 40.8kb + 5.32 kb + 746 b = 327.36600 kb

That's not how the math works! We're going to rework this output. Please see the total emitted size of your .next/static/ folder between two clean builds across these versions and you should see it's less.

Ok thank you, the output was confusing, I see the folder size is smaller. Meanwhile, there is more request sent to the server at the 1st-page load.

This has been changed in the newest Next.js canary. Can you please retry?

Tested on 9.1.8-canary.8:

Page                                                    Size     First Load
โ”Œ ฮป /                                                   818 B        219 kB
โ”œ   /_app                                               22.5 kB      205 kB
โ”œ ฮป /category/[id]                                      3.6 kB       234 kB
โ”œ ฮป /product/[id]                                       3.04 kB      225 kB
โ”” ฮป /search                                             1.12 kB      231 kB
+ shared by all                                         205 kB
  โ”œ static/_buildManifest.js                            305 B
  โ”œ chunks/122263ca4811193d0a92081d2427d6b42500484c.js  114 kB
  โ”œ chunks/commons.js                                   22.4 kB
  โ”œ chunks/framework.js                                 40.8 kB
  โ”œ runtime/main.js                                     4.55 kB
  โ”œ runtime/webpack.js                                  746 B
  โ”” static\<buildId>\pages\_app.js                      22.5 kB

Thanks for the update much easier to understand now!

If they are shared by all then why can't they be made one?

@sheerun for persistent caching reasons โ€” that way one update doesn't invalidate all of your shared javascript. Also, more files are faster to download than a single on H2.

Bigger files are only better for H1.1.

@Timer is it possible to merge runtime/main.js and runtime/webpack.js? it seems runtime/webpack.js is very small all the time.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  ยท  3Comments

renatorib picture renatorib  ยท  3Comments

rauchg picture rauchg  ยท  3Comments

sospedra picture sospedra  ยท  3Comments

flybayer picture flybayer  ยท  3Comments