You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/api/create-placeholder-from-hash.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ The function accepts an options object with the following properties:
14
14
-`hash`: The hash string to decode. If both `image` and `hash` are provided, `hash` takes precedence
15
15
-`hashType`: Specifies whether the hash is a `blurhash` or `thumbhash`. Default is `blurhash`. If `image` is provided, the type is determined from the presence of `data-blurhash` or `data-thumbhash` attributes
16
16
-`size`: The size of the longer edge for BlurHash decoding. Default is `32`. This parameter is ignored for ThumbHash
17
-
-`ratio`: The aspect ratio (width divided by height) for BlurHash. If `image` is provided, this is calculated automatically from the element's dimensions
17
+
-`ratio`: The aspect ratio (width divided by height) for BlurHash. If `image` is provided, this is calculated automatically using: `(width || offsetWidth || size) / (height || offsetHeight || size)`. For optimal performance, set explicit `width` and `height` HTML attributes to avoid falling back to rendered dimensions
18
18
19
19
## Return Value
20
20
@@ -53,6 +53,15 @@ if (placeholder) {
53
53
}
54
54
```
55
55
56
+
```html
57
+
<!-- Ensure the image has width and height attributes for optimal performance -->
58
+
<img
59
+
width="800"
60
+
height="600"
61
+
data-blurhash="LKO2:N%2Tw=w]~RBVZRi};RPxuwH"
62
+
>
63
+
```
64
+
56
65
::: tip
57
66
For server-side rendering, use the specialized functions instead:
58
67
-[`createPngDataUri`](/api/blurhash-create-png-data-uri) from `unlazy/blurhash`
When using client-side BlurHash decoding (`:ssr="false"`), set explicit `width` and `height` attributes for optimal performance. Server-side rendering (enabled by default) is less affected by this, but including these attributes is still recommended as a best practice.
Copy file name to clipboardExpand all lines: docs/integrations/react.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,6 +73,8 @@ The component uses React's `useEffect` hook to initialize lazy loading when moun
73
73
```tsx [BlurHash]
74
74
return (
75
75
<UnLazyImage
76
+
width={800}
77
+
height={600}
76
78
blurhash="LKO2:N%2Tw=w]~RBVZRi};RPxuwH"
77
79
srcSet="image-320w.jpg 320w, image-640w.jpg 640w"
78
80
autoSizes
@@ -82,6 +84,8 @@ The component uses React's `useEffect` hook to initialize lazy loading when moun
82
84
```tsx [ThumbHash]
83
85
return (
84
86
<UnLazyImage
87
+
width={800}
88
+
height={600}
85
89
thumbhash="1QcSHQRnh493V4dIh4eXh1h4kJUI"
86
90
srcSet="image-320w.jpg 320w, image-640w.jpg 640w"
87
91
autoSizes
@@ -91,6 +95,8 @@ The component uses React's `useEffect` hook to initialize lazy loading when moun
91
95
```tsx [Inlined placeholder image]
92
96
return (
93
97
<UnLazyImage
98
+
width={800}
99
+
height={600}
94
100
placeholderSrc="data:image/svg+xml, ..."
95
101
srcSet="image-320w.jpg 320w, image-640w.jpg 640w"
96
102
autoSizes
@@ -102,3 +108,7 @@ The component uses React's `useEffect` hook to initialize lazy loading when moun
102
108
::: tip
103
109
In each example, the `sizes` attribute is automatically calculated given the `auto-sizes` prop.
104
110
:::
111
+
112
+
::: info
113
+
When using BlurHash, set explicit `width` and `height` props for optimal performance. Without these, BlurHash decoding falls back to rendered dimensions, which may cause performance delays on large images.
When using BlurHash, set explicit `width` and `height` props for optimal performance. Without these, BlurHash decoding falls back to rendered dimensions, which may cause performance delays on large images.
109
+
:::
110
+
101
111
::: tip
102
112
In each example, the `sizes` attribute is automatically calculated given the `auto-sizes` prop.
Copy file name to clipboardExpand all lines: docs/integrations/svelte.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,27 +68,37 @@ This component is built using Svelte 5's modern runes syntax:
68
68
::: code-group
69
69
```svelte [BlurHash]
70
70
<UnLazyImage
71
+
width={800}
72
+
height={600}
71
73
blurhash="LKO2:N%2Tw=w]~RBVZRi};RPxuwH"
72
74
srcSet="image-320w.jpg 320w, image-640w.jpg 640w"
73
75
autoSizes
74
76
/>
75
77
```
76
78
```svelte [ThumbHash]
77
79
<UnLazyImage
80
+
width={800}
81
+
height={600}
78
82
thumbhash="1QcSHQRnh493V4dIh4eXh1h4kJUI"
79
83
srcSet="image-320w.jpg 320w, image-640w.jpg 640w"
80
84
autoSizes
81
85
/>
82
86
```
83
87
```svelte [Inlined placeholder image]
84
88
<UnLazyImage
89
+
width={800}
90
+
height={600}
85
91
placeholderSrc="data:image/svg+xml, ..."
86
92
srcSet="image-320w.jpg 320w, image-640w.jpg 640w"
87
93
autoSizes
88
94
/>
89
95
```
90
96
:::
91
97
98
+
::: info
99
+
When using BlurHash, set explicit `width` and `height` props for optimal performance. Without these, BlurHash decoding falls back to rendered dimensions, which may cause performance delays on large images.
100
+
:::
101
+
92
102
::: tip
93
103
In each example, the `sizes` attribute is automatically calculated given the `auto-sizes` prop.
@@ -119,6 +125,10 @@ The component uses Vue's `watchEffect` to handle reactive updates:
119
125
In each example, the `sizes` attribute is automatically calculated given the `auto-sizes` prop.
120
126
:::
121
127
128
+
::: info
129
+
When using BlurHash, set explicit `width` and `height` attributes for optimal performance. Without these, BlurHash decoding falls back to rendered dimensions, which may cause performance delays on large images.
130
+
:::
131
+
122
132
### Preload Image
123
133
124
134
Useful if the `UnLazyImage` is part of e.g. a slider, and you want to preload the next image.
Copy file name to clipboardExpand all lines: docs/placeholders/hash-based.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,15 +25,23 @@ ThumbHash strings are typically shorter and produce higher quality placeholders,
25
25
26
26
By default, unlazy automatically decodes hash strings when a `data-blurhash` or `data-thumbhash` attribute is present on an `<img>` tag.
27
27
28
+
::: warning
29
+
For optimal performance when using BlurHash, always set explicit `width` and `height` attributes on your images. Without these attributes, the library falls back to the rendered dimensions (`offsetWidth`/`offsetHeight`), which can cause BlurHash to decode at full image size instead of the default 32px. This may result in significant performance delays on large images.
30
+
:::
31
+
28
32
::: code-group
29
33
```html [BlurHash]
30
34
<img
35
+
width="800"
36
+
height="600"
31
37
data-src="image.jpg"
32
38
data-blurhash="LKO2:N%2Tw=w]~RBVZRi};RPxuwH"
33
39
>
34
40
```
35
41
```html [ThumbHash]
36
42
<img
43
+
width="800"
44
+
height="600"
37
45
data-src="image.jpg"
38
46
data-thumbhash="1QcSHQRnh493V4dIh4eXh1h4kJUI"
39
47
>
@@ -68,7 +76,7 @@ When initializing unlazy for single images (e.g., in a framework component), you
68
76
:::
69
77
70
78
::: info
71
-
The `hashType` defaults to `blurhash` if not specified.
79
+
The `hashType` defaults to `blurhash` if not specified. For BlurHash, ensure the image element has `width` and `height` attributes set for optimal performance.
72
80
:::
73
81
74
82
### Disabling Hash Decoding
@@ -106,3 +114,19 @@ For a complete list of options, see the API documentation:
Both approaches have distinct characteristics that affect bundle size and user experience:
121
+
122
+
### Client-Side Decoding
123
+
124
+
Requires including the hash decoding library in your JavaScript bundle, which increases bundle size. However, placeholders are visible immediately on page load, providing instant visual feedback to users.
125
+
126
+
### Server-Side Decoding
127
+
128
+
Generates PNG data URIs on the server, keeping your client bundle smaller. The placeholder image is embedded directly in the HTML as a data URI. This approach is ideal when minimizing client-side JavaScript is a priority.
129
+
130
+
::: tip
131
+
ThumbHash is more efficient for both approaches due to its smaller hash size and faster decoding performance compared to BlurHash.
0 commit comments