![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@jbreneman/lazuli-js
Advanced tools
Lazuli is a promise based image lazyloader that works for both images and background images.
npm i @jbreneman/lazuli-js -S
or yarn add @jbreneman/lazuli-js
.
ES modules: import Lazuli from '@jbreneman/lazuli-js';
CJS modules: var Lazuli = require('@jbreneman/lazuli-js');
Global: Make sure it's getting included in your build somehow, then use as normal.
There are 3 different files being built, CommonJS, ES6 module, and UMD. You may need to tell your bundler to grab the right file if you're running into import issues.
Lazuli uses data attributes in place of actual attributes. Basically, take the normal attribute you would normally use and slap a data-
in front of it and you're good to go. Lazuli supports all responsive images attributes as long as they're supported by the browser.
<img class="lazuli" data-src="image.jpg" alt="Basic example">
<img class="lazuli" data-src="image.jpg" data-srcset="image-200.jpg 200w, image-400.jpg 400w, image-800.jpg 800w" data-sizes="(max-width: 680px) 100vw, 50vw" alt="Srcset and sizes!">
Lazuli also supports background images using the exact same syntax, so this will just work:
<div class="lazuli" data-src="image.jpg">
This div will lazyload image.jpg as a background image.
</div>
Lazuli tries to stay out of the way of your styles, meaning you'll need to set things like background-size like you would normally.
Kicking off Lazuli is as simple as:
const lazy = new Lazuli();
By default it looks for the class lazuli
but you can also pass in a selector as a string:
const lazy = new Lazuli('.lazy, .lazy-bg');
You can also pass in an options object for more control over what happens:
const lazy = new Lazuli({
selector: '.lazy, .lazy-bg',
background: false
});
Lazuli returns a promise that resolves once every image is loaded. You can use this to kick off other things once images are loaded or sequentially load groups of images:
new Lazuli('.primary-images').then((res) => {
return new Lazuli('.secondary-images');
}).then((res) => {
return new Lazuli('.tertiary-images');
}).catch((err) => {
console.log('Whoops, something didn't load!', err);
});
{
selector: '.lazuli',
background: true,
img: true,
fancy: false,
load: null
}
Expects a string formatted as a css selector. Uses querySelectorAll internally, so it should be able to deal with pretty much everything.
Expects a boolean. Setting background to false means it will only look for tags, and setting img to false means it only looks for non-
tags. Setting both to false is just silly. ;)
Background images currently support a fancy fade in animation (think medium.com headers). This is still a little experimental—it currently works pretty well but sometimes will break things since it injects it's own <div>
inside the element you attach it to. Highly recommend giving it a shot though! Adding more configuration for this is in the roadmap.
Callback that runs each time an image is loaded. Returns an object with data:
{
image: <Element>
}
Callback that runs when all images have loaded. Returns an object with data:
{
images: [<Element>, <Element>]
}
Submit a PR!
FAQs
A lazy loading library
The npm package @jbreneman/lazuli-js receives a total of 0 weekly downloads. As such, @jbreneman/lazuli-js popularity was classified as not popular.
We found that @jbreneman/lazuli-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.