Optimize Large Contentful Paint (LCP)

The most common causes of a poor LCP are:

  1. Slow server response times
  2. Render-blocking JavaScript and CSS
  3. Slow resource load times
  4. Client-side rendering

For Slow server response times:

  • Use caching and optimized server to improve this.
  • Consider using Caching or CDN services such as cloudflare.
  • Try to keep the initial server response under 1s to get good performance scores.

For Render blocking JavaScript and CSS:

  • Minify CSS
  • Remove unwanted CSS, by creating multiple stylesheets and loading only required CSS files for the given page.
  • CSS and Javascripts that are loaded synchronously will be render blocking. Consider loading critical CSS first, using inline <style> tag and other not so important styles can be deferred by loading them later in the dom. 
  • For the non-critical CSS, you can use loadCSS to load them asynchronous. 

For Slow resource load times, here are some suggestions from web.dev:

The time it takes to load these elements if rendered above-the-fold will have a direct effect on LCP. There are a few ways to ensure these files are loaded as fast as possible:

  • Lazy load images, iframe, embeds etc.
    • Can use loading=”lazy” attribute for image tags or use some JS library that does the same thing. 
  • Optimize and compress images
    • Consider not using an image in the first place. If it’s not relevant to the content, remove it.
    • Compress images
    • Convert images into newer formats (JPEG 2000, JPEG XR, or WebP)
    • Use responsive images (srcset attribute to add more image sizes as per device screen size)
    • Consider using an image CDN
  • Preload important resources
    • Some assets such as fonts, images, are somewhere deep in CSS, and that may load later as per the loading sequence.
    • If you know that a particular resource should be prioritized, use <link rel=”preload”> to fetch it sooner. Many types of resources can be preloaded, but you should first focus on preloading critical assets, such as fonts, above-the-fold images or videos, and critical-path CSS or JavaScript.
<link rel=”preload” as=”script” href=”script.js” /><link rel=”preload” as=”style” href=”style.css” /><link rel=”preload” as=”image” href=”img.png” /><link rel=”preload” as=”video” href=”vid.webm” type=”video/webm” /><link rel=”preload” href=”font.woff2″ as=”font” type=”font/woff2″ crossorigin />
  • Compress text files
    • First, check if your server already compresses files automatically. Most hosting platforms, CDNs, and reverse proxy servers either encode assets with compression by default or allow you to easily configure them.

Cloudflare.com is one such service you can use.

Quizzes