
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
responsive-lazy-loader
Advanced tools
Responsive Lazy Loader is a lightweight script that loads your images when they enter the viewport
Responsive Lazy Loader is a lightweight script that loads your images when they enter the viewport. Not only that but it honours your responsive (srcset) images.
yarn add responsive-lazy-loader
npm install responsive-lazy-loader
Ensure your <img /> tags have a data-src attribute with a path to your image and a default image src. After you've initialised the script, your images will lazy load out of the box. For example:
JS:
import ResponsiveLazyLoader from 'responsive-lazy-loader';
new ResponsiveLazyLoader();
HTML:
<img data-src="http://via.placeholder.com/800x600"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
alt="My Special Image"
/>
Once the image comes into view, it will output:
<img src="http://via.placeholder.com/800x600"
alt="My Special Image"
/>
The script also takes into account srcset and sizes by binding them to data attributes. For example:
<img data-src="http://via.placeholder.com/800x600"
data-srcset="http://via.placeholder.com/400x300 400w, http://via.placeholder.com/800x600 800w"
data-sizes="(max-width: 500px) 400px, 800px"
/>
You can also lazyload picture tags using this ibrary. Please bear in mind that picture tag is not supported in all browsers. In order to make picture tag work you need to use a picture tag polyfill such as picturefill
<picture>
<source data-srcset="http://via.placeholder.com/400x300" media="(max-width: 500px)" />
<source data-srcset="http://via.placeholder.com/800x600" />
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="
data-src="http://via.placeholder.com/200x200"
class=""
alt="" />
</picture>
(src, srcset, sizes, callback, loadOnScroll, resizeDebounce, throttle, threshold)| parameter | description |
|---|---|
src |
Type: stringDefault: 'data-src'The data attribute we want to use for the images src attribute.
|
srcset |
Type: stringDefault: 'data-srcset'The data attribute we want to use for the images srcset attribute.
|
sizes |
Type: stringDefault: 'data-sizes'The data attribute we want to use for the images sizes attribute.
|
callback |
Type: functionDefault: undefinedAn optional function that will be called after each image has been loaded. |
loadOnScroll |
Type: BooleanDefault: trueDo you want to load the images when they are in the viewport or all once? |
resizeDebounce |
Type: INTDefault: 500How long after the user stops resizing their browser window before firing the resize recalculations. |
throttle |
Type: INTDefault: 250How often the scroll event listener fires to check if the image is in view. |
threshold |
Type: INTDefault: 0How much of an offset do you want for the image to be classed as in the viewport? |
MIT
FAQs
Responsive Lazy Loader is a lightweight script that loads your images when they enter the viewport
We found that responsive-lazy-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.