Gabriela Jarzębska
Lead Project Manager

10 min read

August 20, 2020

Speed Up Your React App Using Cloudinary and Lazy Loading

What will you learn

Our shared need for precision, fair play, and heightened tension during matches shapes a willingness to incorporate new sports technologies.

  1. Moreover, this technological enhancement adds a layer of suspense and anticipation.
  2. Intensifying the drama of each match and contributing to a new dimension in our evolving sporting landscape.
  3. Moreover, this technological enhancement adds a layer of suspense and anticipation.
  4. Intensifying the drama of each match and contributing to a new dimension in our evolving sporting landscape.

Problem

According to Neil Patel, akamai.com and Gomez, about 40% of people abandon a website if it takes more than 3 seconds to load. What’s more, half of the web users expect to load the content within 2 seconds!

There are a few elements that can slow down a website and cause that ‘effect’, let’s focus on one thing at the time — images.

This is how can you handle the images so they load faster and don’t slow down the page:

  1. Downsize the larger images to the size needed by your design — even on the desktop, there is no need to go for the biggest image possible.
  2. Remove metadata from delivered images — by default images contain a lot of information useful for cameras and graphics applications, but not for your web users.
  3. Format images to newer formats like JPEG-XR and WebP — common formats like PNG, JPG or GIF are not optimized to be sent wireless.
  4. Lower image quality — many images have an extra-high resolution, however, it’s possible to lower quality without any significant visual impact.
  5. Use lazy loading — allow your images to wait with download until user scrolls down to them, it can really shorten page initialization.
  6. Hold a position of element — so the page doesn’t jump while the images load.
  7. Use the “Blur-up” technique — show a very low-resolution image before the original loads.
  8. On small devices downsize the image even more — mobiles usually have a slower Internet connection, and on small screens, users don’t need super high resolutions.

Optimizing images manually could be a real torture. But hey, as Bobby McFerrin says ‘don’t worry’ — there is a ready band-aid for you.

Solution: Cloudinary

1// Speed Up Technique Code Example 1
2import React from 'react';
3import Img from 'react-cloudinary-lazy-image';
4
5export const LazyImage = () => (
6  <Img
7    cloudName="CloudName"
8    imageName="black-hole"
9    fixed={{
10      width: 800,
11      height: 600,
12    }}
13    alt="black_hole"
14  />
15);
1// Speed Up Technique Code Example 2
2<Img  
3 cloudName={‘CloudName’}  
4 imageName={'black-hole'}  
5 fluid={{    
6 	maxWidth: 800,    
7    height: 300  
8   }}  
9   alt={'black_hole'}
10/>

By clicking this button you agree to receive information from TeaCode about software development and app marketing, the company and its projects to your email. Your data is processed by TeaCode (Postępu 15, 7th floor, 02-676 Warsaw, Poland) to send you relevant content via newsletter (from which you can unsubscribe at any time). You can read more in our Privacy Policy.

It’s customizable!

React-Cloudinary-lazy-image can handle multiple parameters to give you full control over your pictures.

Styles

  • style — define style to wrapper component
  • imgStyle — define style of img element
  • placeholderStyle — define the style of placeholder img element
  • backgroundColor — when set, instead of ‘blur up’ effect desired colour is displayed
  • fadeIn — have a fading effect when the original image is showing up

Cloudinary

  • urlParams — Cloudinary can take many image transformation params. Set what you need in string format, ex.: ‘g_center,c_scale,r_max`
  • imgFormat — it’s image transformation format parameter, but it’s quite important and has own prop in the component
  • quality — Cloudinary quality parameter, same as above

Callbacks

  • onLoad -> callback when the original image is loaded
  • onError -> callback when image failed to load

Links

Table of Contents:

Similar articles:

Subscribe to our newsletter