Cory House has posted following tweet today.
Cory has pointed out a feature in CRA to enable prefetching lazy component, but I learned of a way to apply it on a project.
Scenario
Suppose that you are building a customer intake site.
When a user receives a call, the user can quickly load up the initial customer page
because the site is small because non-essential code is split (lazy loaded).
Validating user (to confirm that the user has the correct customer's page on) will be the idle time to prefetch the lazy component such as tabs to fill in the customer's information, and modal confirmation boxes, etc.
The typical workflow will be,
- User searches for the customer
- Customer page is loaded fast (initial site is small due to code split)
- User confirms with customer if the right page is loaded (providing idle time for prefetch)
- During the idle time, non-essential (not needed right away on load) such as modal or forms in tabs are loaded.
- User can gather data from customer, and enter it quickly.
Thoughts
So this would especially be effective for LOB (line of business) apps with lots of data to enter or look up.
Ones I can think of are,
- Intake screen - where a user confirms the right customer page, and during that time, other forms/modals or non-essential but needed components are loaded.
- Dashboard - where graphs outside the viewport is lazily but prefetched (user analyzing the top graph will give enough time for other graphs outside the viewport to be prefetched during that time)
- Any Master-detail pages - e.g.) A site with lots of image with modal for details such as
- Nav menu - Top level menu is loaded right away, and menu items shown on hover are loaded lazy but prefetched.
Image Credit: Created with the Imgflip Meme Generator
Top comments (7)
With a very small modification we can add support for prefetching to the wrapper lazy load function with retry.
Deterministically prefetching is as easy as
Checkout more details at
Possibly too technical yet to apply to any of my current projects, but definitely something that I will try in the future. Thank you for the post :)
Thank you, joon and glad to have found it useful.
This post also serves as a #devjournal to remind myself and get back to :)
I came here for the Koala! didn't even read the article! OK, I'll read the article. But let it be known I came for the Koala image...
So long as the image peaked your interest, I am fine π
Awesome tip!
Thanks~