knowledge/Lazy loading images in HTML.md

18 lines
649 B
Markdown
Raw Normal View History

# Lazy loading images in HTML
2020-07-27 23:25:24 +02:00
To implement [[Lazy Loading]] to an `<img ... >` tag, add the attribute `loading=lazy`
2020-07-27 23:25:24 +02:00
```html
<img loading=lazy ... >
```
2020-07-27 23:25:24 +02:00
This will load the image when scrolling is near the viewport, using the [Intersection Observer API](https://developers.google.com/web/updates/2016/04/intersectionobserver)
## Further reading
- [Native image lazy-loading](https://web.dev/native-lazy-loading)
2020-07-27 23:25:24 +02:00
## What led to learning this
2020-07-27 23:25:24 +02:00
- Accidentally: a rabbit hole that started at [Jason Crawford's github](https://github.com/jasoncrawford) and ended at an [issue in the owid-grapher repo](https://github.com/owid/owid-grapher/pull/422)