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

rm-react-image

v0.0.6

Published

React image component Performance and SEO friendly

Downloads

2

Readme

rm React image ⚡

npm version npm

🟢 Minimalistic, blazing fast and seo friendly component for React ⚛️

The main objective is to achieve the best possible performance without penalizing SEO. Also, it use W3C img attributes.

Features

  • ⚡️ Optimized for performance
  • 📈 SEO friendly
  • 😪 Lazy load support
  • 🌇 Loading and error placeholders
  • 🔁 Server side support (SSR)
  • ☝ No dependencies, just one possible polyfill: intersection-observer polyfill
  • 🗜️ 5KB gzipped (plus 1KB if you need intersection-observer)

Overview React Slidy is a simple and minimal slider component. The main objective is to achieve the best performance and smoothness on React apps, specially on mobile 📱.

Installation

# Yarn
$ yarn add rm-react-image

# NPM
$ npm i --save rm-react-image

Usage

Common usage with lazy loading for loading="lazy"

import React from 'react';
import { Image } from 'rm-react-image';

const deviceUserAgent = 'googlebot'

const MyImage = ({ alt, height, src, width }) => (
  <Image
    alt={alt}
    src={src} // also support srcset and sizes attributes
    width={width}
    height={height}
    loading="lazy"
    userAgent={deviceUserAgent} />
);

export default MyImage;

Loading "lazy" attribute will act differently depends on User-Agent.

  • If Image detects that User-Agent is a bot, the image will be rendered on SSR and will use native browser lazy loading

  • If the image detects that User-Agent is a user, the image will render when it enters to the viewport.

For that reason, it is important to pass userAgent prop on client and server-side.

Props

| Prop | Type | Default | Description | |:---|:---|:---|:---| | alt | String | | Indicate the alternate fallback content to be displayed if the image has not been loaded | | base64Placeholders | Object | {loading: undefined, error: undefined} | Define Base64 placeholder | | className | String | | Element class name | | decoding | String | | Represents a hint given to the browser on how it should decode the image. | | height | String or Number | | Indicates the rendered height of the image in CSS pixels. | | loading | String | | Determine whether to load the image immediately (eager) or on an as-needed basis (lazy). | | onError | Function | | Callback triggered if an error occurs while loading an external file. | | onLoad | Function | | Callback triggered if image load successfully. | | sizes | String | | This string specifies a list of comma-separated conditional sizes for the image; that is, for a given viewport size, a particular image size is to be used. Read the documentation on the sizes page for details on the format of this string. | | src | String | | Contains the full URL of the image including base URI. | | srcSet | String | | This specifies a list of candidate images, separated by commas (',', U+002C COMMA). Each candidate image is a URL followed by a space, followed by a specially-formatted string indicating the size of the image. The size may be specified either the width or a size multiple. Read the srcset page for specifics on the format of the size substring. | | style | Object | | CSS style properties to inline them. | | userAgent | String | | Device user agent used for improve rendering strategy. | | width | String or Number | | Indicates the rendered width of the image in CSS pixels. |

How to

Use error placeholder

import React from 'react';
import { Image } from 'rm-react-image';

const deviceUserAgent = 'googlebot'
const imageProps = {
  base64Placeholders: {
    error: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
  },
  onError: () => console.log('Image can not be found')
}

const MyImage = ({ alt, height, src, width }) => (
  <Image
    alt={alt}
    src={src} // also support srcset and sizes attributes
    width={width}
    height={height}
    loading="lazy"
    userAgent={deviceUserAgent}
    {...imageProps} />
);

export default MyImage;

Use loading placeholder

import React from 'react';
import { Image } from 'rm-react-image';

const deviceUserAgent = 'googlebot'
const imageProps = {
  base64Placeholders: {
    loading: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'
  },
  onLoad: () => console.log('Image has been loaded'),
}

const MyImage = ({ alt, height, src, width }) => (
  <Image
    alt={alt}
    src={src} // also support srcset and sizes attributes
    width={width}
    height={height}
    loading="lazy"
    userAgent={deviceUserAgent}
    {...imageProps} />
);

export default MyImage;

Not lazy load image for loading="eager"

import React from 'react';
import { Image } from 'rm-react-image';

const deviceUserAgent = 'googlebot'

const MyImage = ({ alt, height, src, width }) => (
  <Image
    alt={alt}
    src={src} // also support srcset and sizes attributes
    width={width}
    height={height}
    loading="eager"
    userAgent={deviceUserAgent} />
);

export default MyImage;

Browser compatibility

Supported browsers are:

  • Chrome
  • Firefox
  • Safari 6+
  • Internet Explorer 11+
  • Microsoft Edge 12+

If some of them doesn't work, please fill an issue.

Contribution

See Contributing Guide.

License

MIT