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

react-progressive-loader

v0.4.3

Published

Utility to load images and React components progressively, and get code splitting for free

Downloads

421

Readme

React Progressive Loader

Defer the load of non-critical images and components if they are off-screen.

This library makes possible to progressively load images, just like Medium does, and React components only when the user is ready to consume the content. Additionaly, take component based code splitting for free. Two at the price of one.

Lazy Loading Images: https://developers.google.com/web/fundamentals/performance/lazy-loading-guidance/images-and-video/

Installation

// with yarn
yarn add react-progressive-loader

// with npm
npm install react-progressive-loader

Usage

// ES2015+ and TS
import { Defer, Img } from 'react-progressive-loader'

Components

Defer

Defers the loading of a React component

Props:

  • render: The content to render
  • renderPlaceholder: The content to render while the content is loading
  • loadOnScreen: Load the content only when the area it is going to be rendered is visible for the user

If case the React component is default-exported in ./comp module

<Defer
  render={() => import('./comp')}
  renderPlaceholder={() => <div>Loading...</div>}
/>

If the component is not default-exported

// './comp.jsx'
export const MyComp = () => 'Loaded!'

// './app.jsx'
<Defer
  render={() => import('./comp').then(({MyComp}) => <MyComp />)}
/>

The render prop can also be a React element

<Defer
  render={() => <img src='my-img.png'></img>}
  renderPlaceholder={() => <div>Loading...</div>}
/>

Load the content only when it is on-screen

<Defer
  render={() => <img src='my-img.png'></img>}
  renderPlaceholder={() => <div>Loading...</div>}
  loadOnScreen
/>

Img

Progressively load images. This component makes a smooth animated transition in the following order:

[Background]->[Placeholder]->[Content]

Props:

  • src: The source of the content
  • placeholderSrc: The source of the image that is going to be showed while the content is loading
  • srcSet: The source of the content (see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-srcset)
  • sizes: A set of source sizes (see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-sizes)
  • bgColor: The color of the backgroud that is going to be showed while the placeholder is loading
  • aspectRatio: A static aspect ratio for image, placeholder, and background color. The aspect ratio provided must be calculated in the following way: height / width
  • loadOnScreen: Load the content only when the area it is going to be rendered is visible for the user
  • alt: Alternative text (see: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-alt)

Any other prop (not listed here) passed to this components will be passed down to the wrapper div

Basic usage

<Img
  src='image.jpeg'
  placeholderSrc='image-placeholder.jpeg'
/>

Transitioning only between background and content. Sometimes you may want to transit only from background to content by finding the dominant color of the image and assigning it to bgColor. This strategy is used by Google image search.

<Img
  bgColor='#FA8054'
  src='image.jpeg'
/>

Load the content only when it is on-screen

<Img
  src='image.jpeg'
  placeholderSrc='image-placeholder.jpeg'
  loadOnScreen
/>

This library uses IntersectionObserver API, for wide browser compatibility consider to add a polyfill

Published under MIT Licence

(c) Yosbel Marin 2018