TCS
TCS

Reputation: 779

NextJs Unused Javascript

I'm using nextjs on vercel.

Making google lighthouse pagespeed test, on my homepage.

It returns "remove unused javascripts", And It lists my other staticprops pages' javascript files like;

privacy-policy.js
gdpr.js
shopping-cart.js etc.

Why It loads other pages, while I am not on those pages? How can I stop it? They must be loaded at only their own url.

Upvotes: 1

Views: 2979

Answers (2)

Chemi Adel
Chemi Adel

Reputation: 2165

NextJS do prefetch on default for linked routes.

you can disable it to avoid loading other pages:

<Link href="path" prefetch={false} />

Upvotes: 5

Antoine
Antoine

Reputation: 130

When using getStaticProps, the build time happens when the package is built.

If you want to build the page only when you go on it, you should use getServerSideProps.

Upvotes: 0

Related Questions