Native Lazy Loading

A presentation at Web Directions Lazy Load in June 2021 in by Anton Ball

Slide 1

Slide 1

Lazy Load Anton Ball ● Web Directions Lazy Load 2021 antonjb

Slide 2

Slide 2

<img src=”doughnut.jpg” alt=”…” loading=”lazy” /> <iframe src”…” loading=”lazy”> antonjb

Slide 3

Slide 3

Thank you antonjb

Slide 4

Slide 4

<img src=”doughnut.jpg” alt=”…” loading=”lazy” /> <iframe src”…” loading=”lazy”> antonjb

Slide 5

Slide 5

Sept 2019 Jan 2020 https://caniuse.com/loading-lazy-attr Feb 2020 Mar 2020 Apr 2020 antonjb

Slide 6

Slide 6

Develop > Experimental Features > Lazy Image Loading antonjb

Slide 7

Slide 7

73% global availability https://caniuse.com/loading-lazy-attr antonjb

Slide 8

Slide 8

Median Image Requests per page 26 desktop https://httparchive.org/reports/state-of-images 24 mobile antonjb

Slide 9

Slide 9

Median Image Transfer Size per page 948kb desktop https://httparchive.org/reports/state-of-images 902kb mobile antonjb

Slide 10

Slide 10

antonjb

Slide 11

Slide 11

addEventListener(‘scroll’, loadImages); Requires JavaScript Poor Performance Potentially unreliable antonjb

Slide 12

Slide 12

const imgObserver = new IntersectionObserver(loadImages); imgObserver.observe(imageToLoad); Requires JavaScript Browser Support antonjb

Slide 13

Slide 13

<img data-src=”doughnut.jpg” alt=”…” /> <noscript> <img src=”doughnut.jpg” alt=”…” /> </noscript> Maintenance antonjb

Slide 14

Slide 14

No JavaScript No NoScript Element Reliable preloading Decide whether to lazy load antonjb

Slide 15

Slide 15

loading: eager | lazy property value antonjb

Slide 16

Slide 16

e u l a v d i l a v n i d n a g n i s s i m , t l u a f e d loading: eager | lazy property value antonjb

Slide 17

Slide 17

native lazy load loading: eager | lazy property value antonjb

Slide 18

Slide 18

FORM FACTOR NETWORK SPEED LITE MODE CONNECTION STATUS antonjb

Slide 19

Slide 19

1 4G - 1,250PX 2 3G - 2,500PX 3 2G - 8,000PX antonjb

Slide 20

Slide 20

antonjb

Slide 21

Slide 21

NO THROTTLING SLOW 3G antonjb

Slide 22

Slide 22

When won’t it work? No Browser Support No JavaScript antonjb

Slide 23

Slide 23

antonjb

Slide 24

Slide 24

loading-attribute-polyfill https://github.com/mfranzke/loading-attribute-polyfill antonjb

Slide 25

Slide 25

<noscript class=”loading-lazy”> <img src=”…” loading=”lazy” width=”250” height=”150” /> </noscript> antonjb

Slide 26

Slide 26

if (‘loading’ in HTMLImageElement.prototype) { // supported } else { // unsupported } antonjb

Slide 27

Slide 27

<img src=”doughnut.jpg” alt=”…” loading=”lazy” /> antonjb

Slide 28

Slide 28

<picture> <source media=”(min-width: 800px)” srcset=”big-doughnut.jpg 1x, bigger-doughnut.jpg 2x”> <img src=”regular-doughnut.jpg” loading=”lazy”> </picture> antonjb

Slide 29

Slide 29

<iframe src”…” loading=”lazy”> antonjb

Slide 30

Slide 30

Gotcha #1 Above the fold loading above the fold 1 below the fo ld antonjb

Slide 31

Slide 31

Gotcha #2 Hidden iFrames e m a r f i n e d d i h antonjb

Slide 32

Slide 32

Gotcha #3 Background images i d un o r kg c a b e g ma antonjb

Slide 33

Slide 33

CSS Aspect Ratio Anton Ball ● Web Directions Hover 2021 antonjb

Slide 34

Slide 34

antonjb

Slide 35

Slide 35

Thank you antonjb