Improves your sites UX by avoiding image pop-in. Generates image hashes for displaying blurry previews when loading images on the frontend. Image hashes condense the shape of your image into around 20-50 bytes.
npm install @danielbiegler/vendure-plugin-blurry-image-lazy-loading
Generates image hashes for displaying blurry previews when loading images on the frontend.
Asset
Entities containing a hash for your frontend.PreviewImageHashStrategy
.
✓ blurry-image-lazy-loading/e2e/thumbhash.e2e-spec.ts (8 tests)
✓ blurry-image-lazy-loading/e2e/blurhash.e2e-spec.ts (8 tests)
✓ blurry-image-lazy-loading/e2e/common.e2e-spec.ts (14 tests)
Test Files 3 passed (3)
Tests 30 passed (30)
The ThumbHash Website has an interactive online comparison generator.
The plugin adds a couple ways to generate hashes for you to the admin api endpoint.
Your admin-client needs the CreateAsset
Vendure permission in order to call the following mutations. See resolver.
See api-extensions.ts for a complete overview of the graphql extensions and types.
You can find the package over on npm and install it via:
The simplest way is relying on the defaults and just adding the plugin with a hashing strategy.
It's possible to pass in further configurations into both the plugin and the strategies, for example:
Please refer to the specific docs for how and what you can customize.
This plugin adds a custom field to the Asset
entity called previewImageHash
, which requires you to generate a database migration. See Vendure's migration documentation for further guidance.
By default the option enqueueHashingAfterAssetCreation
automatically adds hashing tasks to the dedicated job queue for newly added assets.
For existing assets you can produce hashes either synchronously or via the job queue, of which the latter is recommended for production environments, via the admin API:
Now that your assets have hashes you may consume them on your frontend. How and where you consume them exactly is dependent on your setup, but in general it involves the following steps.
ThumbHashStrategy
and its BufferEncoding
set to the default "base64"
you can now decode the hashes with the provided helper like so: