Slide 1

Slide 1 text

Progressive image rendering Render Conf 2017 José M. Pérez · Web dev at Spotify @jmperezperez

Slide 2

Slide 2 text

Images on the web

Slide 3

Slide 3 text

To use or not to use images

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Wrong way of hiding images (1/2) @media (max-width: 480px) { img { display: none; } }

Slide 8

Slide 8 text

Wrong way of hiding images (2/2)

This is the current section

This section might or might not be shown later

.hidden { display: none; }

Slide 9

Slide 9 text

Optimise your images really

Slide 10

Slide 10 text

Picture element and srcset 1 column 2 columns 3 columns

Slide 11

Slide 11 text

1st issue: Keeping in sync markup and CSS Kettlebell Swing

Slide 12

Slide 12 text

2nd issue: Lazy loading

Slide 13

Slide 13 text

Combine regular images and lazy-loaded ones

Slide 14

Slide 14 text

How to lazy load: Basic approach For all images, check whether they are in the viewport (or close enough). If they are, request it. Repeat this onScroll and onResize

Slide 15

Slide 15 text

How to lazy load: IntersectionObserver Don't bind to the scroll event. Subscribe to an event triggered when the image enters the rendered area Supported in Chrome, Opera. In development in Firefox and Edge. Very easy to use as another strategy in your lazy loading library.

Slide 16

Slide 16 text


Slide 17

Slide 17 text

What to show while the image is loading

Slide 18

Slide 18 text


Slide 19

Slide 19 text

Examples of solid color

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text


Slide 23

Slide 23 text

Examples of Progressive Image Loading

Slide 24

Slide 24 text


Slide 25

Slide 25 text

How it's done 1. Use
to render the image 2. Request small thumbnail 3. Draw thumbnail to and apply blur effect 4. Request large image 5. Render large image and hide

Slide 26

Slide 26 text

Markup Overview

Slide 27

Slide 27 text

Did @Medium recently add a new image loading fade- in? I noticed it this morning on mobile and just now again on web. Looks nice. 8:05 PM - 29 Feb 2016 Jason @lang Follow @Medium's articles (although full of high-res images) load up very fast *-* 3:38 AM - 28 Mar 2015 นาธารจะ านแคล @zartre Follow How do users perceive it?

Slide 28

Slide 28 text

I don't know about you but I don't like a bit those blurry (still loading...) images on Medium. Very distracting. 5:40 PM - 29 Dec 2015 Harris Rodis @harrisrodis Follow That blurry image preloading thing on Medium - is it just me or does it make all images load extremely slowly now? 10:53 AM - 5 Feb 2016 James Young @welcomebrand Follow or maybe not?

Slide 29

Slide 29 text


Slide 30

Slide 30 text

With the Progressive JPEG method [...] cognitive fluency is inhibited and the brain has to work slightly harder to make sense of what is being displayed. — From Progressive image rendering: Good or evil?

Slide 31

Slide 31 text

I'm seeing this more and more on Medium posts. Maybe the whole "blur the pictures" stuff isn't a good idea… 7:44 PM - 8 Jan 2016 Damien ​ @Eramdam Follow This @Medium page is fully loaded on my slow connection. Very pretty with those stupid image effects, isn’t it? 2:07 PM - 28 Nov 2015 3 18 Sara Soueidan @SaraSoueidan Follow Reliable?

Slide 32

Slide 32 text

Facebook - Inlining thumbnail image in payload Source: The technology behind preview photos

Slide 33

Slide 33 text

Facebook - Inlining thumbnail image in payload Unfortunately, the standard JPEG header is hundreds of bytes in size. In fact, the JPEG header alone is several times bigger than our entire 200-byte budget. However, excluding the JPEG header, the encoded data payload itself was approaching our 200 bytes.

Slide 34

Slide 34 text

Facebook - Inlining thumbnail image in payload Header (mainly Quantization Table and Huffman Table) Compressed Data Client (mobile app) GraphQL

Slide 35

Slide 35 text

Generating tiny thumbnails JPG 464 B 532 B 428 B 409 B 456 B 692 B WebP 112 B 154 B 106 B 96 B 116 B 202 B

Slide 36

Slide 36 text

Generating tiny thumbnails JPG 464 B 532 B 428 B 409 B 456 B 692 B WebP 112 B 154 B 106 B 96 B 116 B 202 B

Slide 37

Slide 37 text

Getting creative with SVGs

Slide 38

Slide 38 text


Slide 39

Slide 39 text

How it works window.onload = function() { var path = document.querySelector('path'); var length = path.getTotalLength(); // Clear any previous transition = = 'none'; // Set up the starting positions = length + ' ' + length; = length; // Trigger a layout so styles are calculated & the browser // picks up the starting position before animating path.getBoundingClientRect(); // Define our transition = = 'stroke-dashoffset 7s ease-in-out'; // Go! = '0'; }; E D I T O N HTML CSS JS Result More info:

Slide 40

Slide 40 text

Drawing bitmap images Canny Edge Detector

Slide 41

Slide 41 text

Drawing bitmap images Source:

Slide 42

Slide 42 text

How to draw bitmaps 1. Find edges with canny edge detector 2. Create lines 3. Use JS and SVG to animate ...

Slide 43

Slide 43 text

Should we do this? Just because you can it doesn't mean you should

Slide 44

Slide 44 text

Summary Reduce requests Choose the right format and optimise Embrace responsive images Try to lazy load Innovate!

Slide 45

Slide 45 text

The Web is fun.

Slide 46

Slide 46 text

Thanks! @jmperezperez