callmecavs/layzr.js is tracked by TopGit as an image tool, with 5.5k stars on GitHub, written primarily in JavaScript. A modern lazy loading library for images.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Examples progress like a coffee addiction: small -> medium -> large
Install
Layzr was developed with a modern JavaScript workflow in mind. To use it, it's recommended you have a build system in place that can transpile ES6, and bundle modules. For a minimal boilerplate that fulfills those requirements, check out outset.
Install Layzr, and add it to your package.json dependencies.
$ npm install layzr.js --save
Then import it into the file where you'll use it.
import Layzr from 'layzr.js'
Setup Images
Layzr intelligently chooses the best image source available based on an image's data attributes and browser feature detection.
In browsers that support srcset, if available, it will be used to determine the source.
In browsers that don't, the normal or retina source will be chosen based on the devicePixelRatio and availability.
Note that all attribute names are configurable via the options passed to Layzr. To indicate potential sources, add the following attributes to your images:
Name
Required
Optional
data-normal
✓
data-retina
✓
data-srcset
✓
data-normal
Put the normal resolution source in the data-normal attribute.
<img data-normal="normal.jpg">
Note that Layzr selects elements using this attribute. Elements without it won't be tracked, and will never load.
data-retina
Add the retina/high resolution source in the data-retina attribute.
Customize the attribute the normal resolution source is taken from.
const instance = Layzr({
normal: 'data-normal'
})
retina
Customize the attribute the retina/high resolution source is taken from.
const instance = Layzr({
retina: 'data-retina'
})
srcset
Customize the attribute the source set is taken from.
const instance = Layzr({
srcset: 'data-srcset'
})
threshold
Adjust when images load, relative to the viewport. Positive values make images load sooner, negative values make images load later.
Threshold is a percentage of the viewport height, identical to the CSS vh unit.
const instance = Layzr({
threshold: 0
})
Events
Layzr instances are extended with Knot.js, a browser-based event emitter. Use the event emitter syntax to add and remove handlers. Review the emitter syntax here.
Layzr emits the following events:
src:before
src:after
src:before
This event is emitted immediately before an image source is set. The image node is passed to the event handler.
instance.on('src:before', (element) => {
// 'this' is your Layzr instance
// 'element' is the image node
// ...
})
Load event handlers should be attached using this event. See the example, and note the caveats associated with image load events before proceeding.
src:after
This event is emitted immediately after an image source is set. The image node is passed to the event handler.
instance.on('src:after', (element) => {
// 'this' is your Layzr instance
// 'element' is the image node
// ...
})
Note that the image is not necessarily done loading when this event fires.
API
All API methods are chainable, including those from the emitter.
.handlers(flag)
Add or remove the scroll and resize event handlers.
instance
.handlers(true) // 'true' adds them
.handlers(false) // 'false' removes them
.check()
Manually check if elements are in the viewport.
This method is called while the window is scrolled or resized.
instance.check()
.update()
Update the elements Layzr is checking.
instance.update()
Dynamically added elements should be handled using this method. See the example.
Browser Support
Layzr depends on the following browser APIs:
classList
ES5 array methods: forEach, slice
requestAnimationFrame
It supports the following natively:
Chrome 24+
Firefox 23+
Safari 6.1+
Opera 15+
Edge 12+
IE 10+
iOS Safari 7.1+
Android Browser 4.4+
To support older browsers, consider including polyfills/shims for the APIs listed above. There are no plans to include any in the library, in the interest of file size.
The most recent commit recorded on callmecavs/layzr.js was 8.8 years ago, based on the GitHub push timestamp. The repository has 232 forks — one of the better signals of community interest.
How many stars does callmecavs/layzr.js have?
callmecavs/layzr.js has 5.5k GitHub stars — refresh the page for the live number, or check github.com/callmecavs/layzr.js. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What else is in the Image Tools space?
callmecavs/layzr.js is tracked by TopGit under the Image Tools category, alongside 3 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What language is callmecavs/layzr.js written in?
callmecavs/layzr.js is written primarily in JavaScript. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is callmecavs/layzr.js associated with?
GitHub's repository topics for callmecavs/layzr.js: "image", "lazy", "load". TopGit's editorial category is Image Tools.
Where do I read more about callmecavs/layzr.js?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/callmecavs/layzr.js is the definitive source.
Why is callmecavs/layzr.js categorized under Image Tools?
TopGit places callmecavs/layzr.js in the Image Tools category based on its GitHub topics and description (tagged: "image", "lazy", "load"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Want a second opinion on layzr.js?
Ask an AI that can read this page — one click and you get its take on layzr.js.