|
1 | 1 | # Docusaurus Native Ideal Image Plugin |
2 | 2 |
|
3 | | -A [Docusaurus](https://docusaurus.io/) plugin for pre-processing images to multiple formats, sizes and low quality image placeholders, replacing [ideal-image](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-ideal-image) |
| 3 | +A [Docusaurus](https://docusaurus.io/) plugin for pre-processing images to multiple formats, sizes and low quality image placeholders |
| 4 | + |
| 5 | +This replaces the official [@docusaurus/plugin-ideal-image](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-ideal-image) through modern browser native [`srcset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/srcset) and [lazy loading](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/img#loading) |
| 6 | + |
| 7 | +## Why |
| 8 | + |
| 9 | +The official [@docusaurus/plugin-ideal-image](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-ideal-image) has some limitations and bugs which this package was made to solve: |
| 10 | + |
| 11 | +- [Image flashing when navigating back and forward](https://github.com/facebook/docusaurus/issues/10214) |
| 12 | +- Buggy low bandwidth detection that replaces the image with a 'Click to load' text instead of just loading it. |
| 13 | +- Doesn't support newer image formats that has better compression ratios like WebP and AVIF |
| 14 | + |
| 15 | +Apart from these, using browser native features is more performant, and resulting in smaller bundle sizes |
4 | 16 |
|
5 | 17 | ## Usage |
6 | 18 |
|
@@ -55,11 +67,16 @@ By default, this will transform the image into a jpeg source and a webp source a |
55 | 67 |
|
56 | 68 | ```html |
57 | 69 | <picture |
58 | | - class="native-ideal-img" |
59 | | - style="--lqip: url(data:image/webp;base64,UklGRj4AAABXRUJQVlA4IDIAAADQAQCdASoQAAwABUB8JZQAAudcoVPyIAD+uVyF4iJZsGTWpdieB7utExa6oMeh0PusAA==);" |
| 70 | + class="native-ideal-img" |
| 71 | + style="--lqip: url(data:image/webp;base64,UklGRj4AAABXRUJQVlA4IDIAAADQAQCdASoQAAwABUB8JZQAAudcoVPyIAD+uVyF4iJZsGTWpdieB7utExa6oMeh0PusAA==);" |
60 | 72 | > |
61 | | - <source srcset="assets/native-ideal-image/some-image-b0600-2160.webp" type="image/webp" /> |
62 | | - <img loading="lazy" src="assets/native-ideal-image/some-image-6ee75-2160.jpeg" width="2160" height="1620" /> |
| 73 | + <source srcset="assets/native-ideal-image/some-image-b0600-2160.webp" type="image/webp" /> |
| 74 | + <img |
| 75 | + loading="lazy" |
| 76 | + src="assets/native-ideal-image/some-image-6ee75-2160.jpeg" |
| 77 | + width="2160" |
| 78 | + height="1620" |
| 79 | + /> |
63 | 80 | </picture> |
64 | 81 | ``` |
65 | 82 |
|
|
0 commit comments