Refactor/lazy load page components#222
Conversation
|
@frb21 are the screenshots from production or dev setup? |
The screenshots are from my local dev setup sir... |
There was a problem hiding this comment.
Hmmmm, I don't know about using this method. It might be too huge of a change that might break other else's code. Wouldn't be:
const <component> = lazy(() => import('path-to-component'));be better? Then wrapping just one <Suspense> over the whole return function than wrapping every <Route>? I wanna hear your thoughts on this.
… for whole return function
Hi po, I've updated the PR based on your feedback about the lazy loading approach. Changes include:
|
Would be better if we can see the prod build performance improvement. Also, it might be better to measure first the components that are really problematic. If they need optimization, then we do proceed. I'm not a fan of premature optimization, but I don't want to gate keep this very good contribution. I'm leaving to other maintainers. |
|
Per @codegino could you please deploy to vercel and upload the link here? We see the bundle size diff pero would also like to see if how big of a difference it is with initial loading time. Either way I'm impartial to this improvement. Since majority of the website is static content, we could look into prerendering? |
hello po @niculistana @codegino, is the link for the deployed build on Vercel already available? |
|
@frb21 familiar po kayo sa vercel? Pwede po kayong gumawa ng account tapos create ka ng project tapos connect nyo yung fork nyo. For example ito yung fork ko: https://github.com/adobocorp/bettergov Tapos connect ko sa vercel. After deploy may custom link kayo: https://bettergov-adobo.vercel.app/. |
ay okay po, salamat po sir! |
|
Hello po @niculistana @codegino, I tried to compare the separate versions after deployment. I navigated to the different components sa two versions and here's what I have found: |
|
Salamat @frb21 paki send po url dito from vercel |
https://bettergov-main.vercel.app/ |
|
Does main have your lazy-load changes? If so can you verify the following report? Ran pagespeed against main and prod and I don't really see the a big difference because our pages contain bundle sizes that aren't too heavy. Main: https://pagespeed.web.dev/analysis/https-bettergov-main-vercel-app/wuw4y9oewf?form_factor=mobile Prod: https://pagespeed.web.dev/analysis/https-bettergov-ph/oweys6ywz0?form_factor=mobile Not sure if this is the best recommendation but for now why not run a bundle analyzer and see which bundle is the heaviest and lazy-load just that route? Eager loading is fine for a majority of small bundles. |


Summary
This PR implements lazy loading for page components, addressing the performance issue described in #212 . The goal is to optimize initial load time by reducing the main bundle size, while still supporting smooth navigation between routes.
Changes
App.tsxto useReact.lazyandSuspensefor route-based code splitting..gitignoreto exclude build artifacts (dist/,dist-main/,dist-lazy) and keep the repository clean.Performance Comparison
Non-Lazy Load:

Lazy Load:

Observations