loading...
Cover image for Prefetch lazy-loaded component

Prefetch lazy-loaded component

dance2die profile image Sung M. Kim ・2 min read

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,

  1. User searches for the customer
  2. Customer page is loaded fast (initial site is small due to code split)
  3. User confirms with customer if the right page is loaded (providing idle time for prefetch)
  4. During the idle time, non-essential (not needed right away on load) such as modal or forms in tabs are loaded.
  5. 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,

  1. 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.
  2. 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)
  3. Any Master-detail pages - e.g.) A site with lots of image with modal for details such as
  4. 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

Discussion

pic
Editor guide
Collapse
fly profile image
joon

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 :)

Collapse
dance2die profile image
Sung M. Kim Author

Thank you, joon and glad to have found it useful.

This post also serves as a #devjournal to remind myself and get back to :)

Collapse
httpjunkie profile image
Eric Bishard

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...

Collapse
dance2die profile image
Sung M. Kim Author

So long as the image peaked your interest, I am fine 😁

Collapse
lineldcosta profile image
lineldcosta

Awesome tip!

Collapse
dance2die profile image