Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Optimizing For Core Web Vitals

Optimizing For Core Web Vitals

In this hands-on talk, we cover tips & tricks for optimizing your user-experience to meet the Core Web Vitals. We use tools like Lighthouse & DevTools, show you code snippets for fixes, and highlight how you too can get fast and stay fast.

Optimizing for quality of user experience is key to the long-term success of any site on the web. Whether you're a business owner, marketer, or developer, Core Web Vitals can help you quantify the experience of your site and identify opportunities to improve.

Video: https://www.youtube.com/watch?v=AQqFZ5t8uNc
Related article: https://web.dev/optimize-cls/

Addy Osmani

July 08, 2020
Tweet

More Decks by Addy Osmani

Other Decks in Technology

Transcript

  1. News Home | News | Sport | Travel | Culture

    | More News Today’s the day for you. May 14 is National Dance Like a Chicken Day! While we could make this up right now, we’re not. So break out your best Chicken Dance. This day entertains from start to finish with people flapping their arms and strutting chicken-like. Everyone has probably danced the Chicken Dance at least once in their lifetime — especially if you’ve attended a wedding
  2. News Home | News | Sport | Travel | Culture

    | More News Today’s the day for you. May 14 is National Dance Like a Chicken Day! While we could make this up right now, we’re not. So break out your best Chicken Dance. This day entertains from start to finish with people flapping their arms and strutting chicken-like. Everyone has probably danced the Chicken Dance at least once in their lifetime — especially if you’ve attended a wedding
  3. Images Without Dimensions Ads, Embeds, iFrames Without Dimensions Dynamically Injected

    Content Web Fonts Causing FOIT/FOUT W H What causes poor CLS?
  4. <!-- Old best practice --> <img src="shoe.jpg" width="640" height="360" alt="Shoe">

    <!-- Then came responsive design practice --> <img src="shoe.jpg" alt="Shoe"> <style> img { width: 100%; /* or max-width: 100%; */ height: auto; } </style>
  5. Image Aspect Ratio = ratio of width to height Want

    a 16:9 ratio? If dress.jpg has 360px height… width = 360 * (16 / 9) = 640px 360px ? px
  6. <!-- The UA stylesheets of browsers will add a default

    aspect ratio based on the element's existing width and height attributes --> <style> img { aspect-ratio: attr(width) / attr(height); } </style>
  7. <!-- Modern best practice --> <!-- e.g set a 640:360

    i.e a 16:9 - aspect ratio --> <img src="shoe.jpg" width="640" height="360" alt="Shoe">
  8. Chloe’s approach to image loading Fixed size parent container Color

    similar to final image Responsive image Also has dimensions specified
  9. <style> .container { display: block; width: 720px; height: 90px; background:

    #ccc; overflow:hidden; } </style> <div class="container"> <iframe src="..."> </div> Container Content in Container Content in Container - different size
  10. Reserve space of promotional banner CLS Banner was inline and

    API call originally came from a client-side service using JavaScript Moved this API call to the server and reserved space With a simple height setting.
  11. To improve CLS, Chloe acted on many elements: 1. Reserving

    the space of the Promo Content in terms of ratio. 2. Adopt Skeleton Pattern to render some colored rectangles prior to Product images loading. 3. Reserve the space for the Promo Banner async request before receiving the message. 4. Reserved the space for the Filters dynamic component. CLS
  12. Slow Server Response Times Render-blocking JavaScript and CSS Slow Resource

    Load Times Client-side Rendering What causes poor LCP?
  13. Homepage LCP Before 1. LCP: 10s 2. LCP Related Node

    Start Request time: 5.3s 3. LCP Related Node Size: 591KB. 4. LCP Related Node Content Download time: 4437ms. LCP
  14. Elements that affect LCP 1. <img> elements 2. <image> elements

    inside an <svg> element 3. <video> elements (if specified, the poster image is used to measure LCP) 4. An element with a background image loaded via the url() function (as opposed to a CSS gradient) 5. Block-level elements containing text nodes or other inline-level text elements
  15. For many sites, images are the largest element in view

    when the page has finished loading. Optimize them.
  16. Image Optimizations 1. Adopt an image CDN. 2. Adopted WebP

    by default. 3. Resized images to 282px intrinsic size - while in the viewport images have size of 152px max (right balance on Retina devices). 4. They tuned in the Lazy loader to better avoid requesting offscreen images. Total ATF Image downloaded size 14.5KB Each product page now weighs 57% less
  17. Homepage LCP After (Redesign) 1. LCP: 4s 2. LCP Related

    Node Start Request Time: 1360s 3. LCP Related Node Size: 238KB 4. LCP Related Node Content Download time: 1679 ms LCP
  18. .topBannerWrapper & { height: topbanner(minHeight); z-index: 1; opacity: 1; @include

    backgroundLoading(); critical: this; &.laif-topbanner { .imgWrapper, .overlay { opacity: 0; transition: opacity 300ms ease-in; critical: this; } &.laif-loaded { .imgWrapper, .overlay { opacity: 1; } &::before { content: unset; LCP
  19. for (var i = 0; i < CssFiles.media.length; i++) {

    var link = document.createElement("link"); link.href = CssFiles.media[i]; link.type = "text/css"; link.rel = "stylesheet"; link.media = "print"; link.onload = link.media = "all"; document.getElementsByTagName("head") [0].appendChild(link); } LCP
  20. Overall Core Web Vitals Improvements - Lab Before CLS +

    LCP Improvements After CLS fix on Promo Banner and Filters widgets CLS 0.4 -> 0 Critical CSS, Image resizing etc. LCP 2.9s -> 1.5s
  21. Largest Contentful Paint CrUX First Input Delay CrUX Cumulative Layout

    Shift CrUX Overall Core Web Vitals Improvements - Field
  22. CrUX Dashboard & CrUX API LCP const KEY = apiKey;

    async function (requestBody) { const endpointUrl = 'https://chromeuxreport.googleapis.com/v1/ records:queryRecord'; const resp = await fetch(`${endpointUrl}?key=${KEY}`, { method: 'POST', body: JSON.stringify(requestBody), }); const json = await resp.json(); if (!resp.ok) { throw new Error(json.error.message); } return json;
  23. Template slides The following slide is to be used for

    marketing and promotional purposes only.
  24. Heading here Three columns When the cheese comes out everybody's

    happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Heading here When the cheese comes out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Heading here When the cheese comes out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi.
  25. Heading here Three columns — callout When the cheese comes

    out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Heading here When the cheese comes out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Heading here When the cheese comes out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi.
  26. Heading here Four columns When the cheese comes out everybody's

    happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Heading here When the cheese comes out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Heading here When the cheese comes out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Heading here When the cheese comes out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi.
  27. protected void onTryUpdate(int reason) throws RetryException { // Do some

    awesome stuff int foo = 15; publishArtwork(new Artwork.Builder() .title(photo.name) .imageUri(Uri.parse(photo.image_url)) .viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(“http://500px.com/photo/" + photo.id))) .build()); scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS); }
  28. When the cheese comes out everybody's happy st. agur blue

    cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Mobile Close Up
  29. When the cheese comes out everybody's happy st. agur blue

    cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Mobile Close Up 2
  30. When the cheese comes out everybody's happy st. agur blue

    cheese dolcelatte. A. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. 
 B. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Mobile Close Up Callouts A B
  31. When the cheese comes out everybody's happy st. agur blue

    cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Laptop Large
  32. When the cheese comes out everybody's happy st. agur blue

    cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Laptop Small
  33. When the cheese comes out everybody's happy st. agur blue

    cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Monitor
  34. protected void onTryUpdate(int reason) throws RetryException { // Do some

    awesome stuff int foo = 15; publishArtwork(new Artwork.Builder() .title(photo.name) .imageUri(Uri.parse(photo.image_url)) .viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(“http://500px.com/photo/" + photo.id))) .build()); scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS); }
  35. Photo & Text 
 When the cheese comes out everybody's

    happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi.
  36. When the cheese comes out everybody's happy st. agur blue

    cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Bar Chart A B C D E 0 10 20 30 40
  37. Table Large Text Text Text Text Text Text Here Text

    Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here
  38. Table Small Text Text Text Text Here Text Here Text

    Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here Text Here When the cheese comes out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi.
  39. Firstname Lastname Title / Position 
 
 @socialhandle Firstname Lastname

    Title / Position 
 
 @socialhandle Firstname Lastname Title / Position 
 
 @socialhandle
  40. Firstname Lastname Title / Position 
 
 @socialhandle Firstname Lastname

    Title / Position 
 
 @socialhandle Firstname Lastname Title / Position 
 
 @socialhandle Firstname Lastname Title / Position 
 
 @socialhandle
  41. Slide Title 1. Here’s the thing 
 2. And because

    of that, this 
 3. At the same time, there’s this thing 
 4. That pretty much sums it up
  42. Heading here Heading here Two columns When the cheese comes

    out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. When the cheese comes out everybody's happy cut the cheese babybel taleggio bavarian bergkase st. agur blue cheese cheese on toast caerphilly. Cheddar. When the cheese comes out everybody's happy st. agur blue cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. When the cheese comes out everybody's happy cut the cheese babybel taleggio bavarian bergkase st. agur blue cheese cheese on toast caerphilly. Cheddar.
  43. When the cheese comes out everybody's happy st. agur blue

    cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. When the cheese comes out everybody's happy cut the cheese babybel taleggio bavarian bergkase st. agur blue cheese cheese on toast caerphilly. Cheddar. • When the cheese comes out everybody's happy • Who moved my cheese stinking bishop queso st. agur blue cheese cheesy grin caerphilly brie edam. • Cauliflower cheese pepper jack emmental the big cheese the big cheese the big cheese mozzarella babybel. Bavarian bergkase cheesy grin caerphilly pecorino edam monterey jack cottage cheese halloumi. Bocconcini croque monsieur pecorino. Half paragraph / half bullets
  44. When the cheese comes out everybody's happy st. agur blue

    cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. When the cheese comes out everybody's happy cut the cheese babybel taleggio bavarian bergkase st. agur blue cheese cheese on toast caerphilly. Cheddar. Half paragraph / half quote “Mascarpone halloumi brie taleggio edam halloumi cheese and biscuits gooey cheese.”
  45. When the cheese comes out everybody's happy st. agur blue

    cheese dolcelatte. Cheeseburger cheesy grin babybel caerphilly blue castello mozzarella pepper jack babybel. Stilton melted cheese cut the cheese stilton cheesy feet cheese strings say cheese halloumi. Mobile Close Up 2