DEV Community

Discussion on: How to use React Suspense for Code-Splitting?

Collapse
 
asp2809 profile image
Anshu S Panda

Thanks for the post.
As per what I can see if this is the scenario then I can also lazy load every default export component in my project. So, what would you recommend, lazy loading every component or just the ones which increase my bundle size by a good amount?

Collapse
 
sergiodxa profile image
Sergio Daniel Xalambrí • Edited

Start lazy loading at the router level, then only lazy load big components. Remember every lazy loaded component will need a new request to the server, lazy loading everything could make your app slower, you need to find the right spot for your app.

Collapse
 
marinovicmarko profile image
Marko Marinovic

I agree with Sergio. You should find the best use case for your app. Starting at the router level is perfect. I used this approach for my website because blog post content is in a form of .md files and it would be bad bundle it all together. It kinda mimics the behavior you would get by storing blog content in database and retrieving it on demand.

Collapse
 
asp2809 profile image
Anshu S Panda

Thanks for the reply. Now it's clear to me how and where to do the lazy loading.