npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@doughlass/ngx-lazy-load-images

v1.0.0

Published

Image lazy load library for Angular 15+.

Downloads

1

Readme

ngx-lazy-load-images

FOSSA Status

ngx-lazy-load-images is a image lazy load library for Angular 2+.

The library allows to lazy load images from your web application using the MutationObserver and the IntersectionObserver. Images will be loaded as soon as they enter the viewport in a non-blocking way.

It supports <img> tags as well as background images.

Installation

You can install the library via npm with this command:

npm install ngx-lazy-load-images --save

Usage

1. Import the LazyLoadImagesModule

Import LazyLoadImagesModule from the ngx-lazy-load-images package, and add it to the NgModule imports array of your component.

import { NgModule } from '@angular/core';
import { LazyLoadImagesModule } from 'ngx-lazy-load-images';

@NgModule({
  imports: [
    LazyLoadImagesModule
  ]
})
export class AppComponent {}

2. Use the lazy-load-images directive

Add the lazy-load-images directive to the tag containing all the DOM image nodes to lazy load:

<!-- Image tags -->
<div class="image-list" lazy-load-images>
  <img *ngFor="let imageUrl in images" [attr.data-src]="imageUrl">
</div>

<!-- Background images -->
<div class="image-list" lazy-load-images>
  <div *ngFor="let imageUrl in images" [attr.data-background-src]="imageUrl"></div>
</div>

The container can have any HTML or components inside along with the images. But the less nodes inside the directive, the faster it will be.

Intersection Observer Configuration

If you want to make some configuration changes to the Intersection Observer, you can do it by passing an object to the lazy-load-images directive. The object takes the Intersection Observer configuration parameters as keys.

<div class="image-list" [lazy-load-images]="{ rootMargin: '50px' }"></div>

3. Set the data-src or data-background-src attribute

Set the data-src or data-background-src attribute in the images or tags that you want to lazy load.

The data-src attribute allows to lazy load images inside <img> tags. You can define it by passing a variable to the attribute, interpolating a variable, or inserting the URL directly:

<img [attr.data-src]="imageUrlVariable">
<img attr.data-src="{{ imageUrlVariable }}">
<img data-src="https://example.com/cute_kitten.jpg">

The data-background-src attribute lazy loads background images inside any HTML tag. It works the same way as the data-src attribute:

<div [attr.data-background-src]="imageUrlVariable"></div>
<div attr.data-background-src="{{ imageUrlVariable }}"></div>
<div data-background-src="https://example.com/cute_kitten.jpg"></div>

4. Have fun 🎉

Performance

Browser Compatibility

This library has been tested and known to work in the latest version of all major browsers.

The WICG Intersection Observer Polyfill is bundled within the module to use the Intersection Observer API in the non-compatible browsers. Avoid importing it in your application too, as it may cause unexpected issues.

However, the compatibility with older browsers is limited by the Mutation Observer support, which is known to work in:

License

MIT

FOSSA Status