Hi there! πŸ‘‹ 😊

Did you know that if you load images after the page is loaded, the user will see the content earlier and SEO tools will detect that the page loads faster? πŸš€πŸ“ˆ

Before we start, I would highly recommend you to check out runnable example for the solution on our website:
React β€” async image loading

In this article, I want to show you how to create a simple component in React by which the graphics are loaded after all resources are loaded.

That approach speeds up page loading by splitting the loading process into two steps:

  • page loading (without async images) β€” we see all necessary things in the right order sooner,
  • async images loading β€” images are loaded when the page is ready.

Final effect:

Images async loading proof in Google Chrome DevTools β€” loaded after blue and red lines

Arrows mark lines when images are loaded after rendering the page (when it’s ready).

Below I present you a solution in which I create an in-memory only image that, after is loaded, signals to display the proper image in React on the web page.

Practical example:

I recommend copying the solution to your local React project, open developer tools in your browser and then run the application to see the result.

If you found this article useful and would like to receive more content like this, you could react to this post, which would make me very happy. 😊

See you in the next posts! πŸ–

Write to us! βœ‰

If you have any problem to solve or questions that no one can answer related to a React or JavaScript topic, or you’re looking for a mentoring write to us on dirask.com -> Questions

dirask.com β€” we help you to solve coding problems βœ”οΈπŸš€. Ask question dirask.com/questions