Menu

Scrolling My Blog Index Prefetched All 51 Posts. One Config Line Cut It to 90 kB.
πŸ“°

Scrolling My Blog Index Prefetched All 51 Posts. One Config Line Cut It to 90 kB.

DEV Community: nextjsΒ·Mohsen FallahnejadΒ·7 days ago
#6O5Sknu4
#devtonextjs#devto#dev#route#every
Reading 0:00
15s threshold

The /blog page on this site is one long list: 51 posts, 51 <Link> s. I opened it in a production build, scrolled from top to bottom without clicking anything, and counted the network requests:

RSC requests: 83 posts prefetched: 51 of 51 transferred: 576 kB (gzip; 2.7 MB once decoded)

Enter fullscreen mode

Exit fullscreen mode

Every single post got downloaded in the background because its link scrolled past. Nobody reads 51 posts in a row. That's over half a megabyte spent on pages that, for almost every visitor, will never be opened.

The wrong turn: prefetch={false} everywhere

The standard advice, which an older post on this blog repeats, is to switch prefetching off for big lists:

< Link href = { `/ ${ post . slug } ` } prefetch = { false } > { post . title } </ Link >

Enter fullscreen mode

Exit fullscreen mode

That fixes the bandwidth, but it trades it for something worse. Without a prefetch, the router has nothing for that route when you click.…

Continue reading β€” create a free account

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