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

@anakinyuen/progressive-image

v0.0.1

Published

Enriches the native `img` element by using multiple Progressive Image Rendering strategies

Downloads

12

Readme

progressive-image

code style: prettier

The customized build-in element that enriches the native img element by using multiple Progressive Image Rendering strategies.

example

progressive-image example in Chrome with Fast 3G throttling

Installation

npm

$ npm install progressive-image

Direct include

Simply download and include with a script tag and a link tag inside the head tag.

<head>
  <link rel="stylesheet" type="text/css" href="progressive-image.css" />
  <script src="progressive-image.js"></script>
</head>

or

Using import statement

You may also import progressive-image directly to your source code

import 'progressive-image';
<head>
  <link rel="stylesheet" type="text/css" href="progressive-image.css" />
  <!-- <script src="progressive-image.js"></script> -->
</head>

Usage

Create img in html

<img
  is="progressive-image"
  width="474"
  height="600"
  src="The_Scream.jpg"
  alt="The Scream"
  data-blurry-src="The_Scream-189px.jpg"
  sizes="(min-width: 415px) 50vw, 80vw"
  srcset="
    The_Scream-474px.jpg     474w,
    The_Scream-606px.jpg     606w,
    The_Scream-808px.jpg     808w,
    The_Scream-10025px.jpg 10025w
  "
/>

Create img in js

const progressiveImage = document.createElement('img', {
  is: 'progressive-image',
});
progressiveImage.width = 474;
progressiveImage.height = 600;
progressiveImage.src = 'The_Scream.jpg';
progressiveImage.alt = 'The Scream';
progressiveImage.dataset.blurrySrc = 'The_Scream-189px.jpg';
progressiveImage.sizes = '(min-width: 415px) 50vw, 80vw';
progressiveImage.srcset = `
  The_Scream-474px.jpg     474w,
  The_Scream-606px.jpg     606w,
  The_Scream-808px.jpg     808w,
  The_Scream-10025px.jpg 10025w
`;

Key Features

  • no dependency
  • minimal size: weighing 1.8KB only
  • multiple Progressive Image Rendering strategies: support CSS Placeholder Shimmer and Low quality image placeholder (LQIP)
  • lazy load images: Intersection Observer is used to trigger image loads
    • you may want to include Intersection Observer polyfill for browsers which not natively support Intersection Observer
  • auto fallback: work exactly the same as img do if Custom elements is not supported

Attributes

is (is="progressive-image")

Specify that a standard HTML element (img) should behave like a registered custom built-in element (progressive-image).

See Using custom elements for more details

src

Same as src attribute on the img tag.

srcset

Same as srcset attribute on the img tag.

sizes

Same as sizes attribute on the img tag.

See Responsive Images for usage of sizes and srcset.

alt

Same as alt attribute on the img tag.

data-blurry-src

Optional attribute

The data-blurry-src attribute defined the source for Low quality image placeholder(LQIP) of the img element. By default, the image of data-blurry-src is immediately downloaded and shown in blurry form. The final image will start download after LQIP is shown. Once ready, the LQIP will fade out and show the final image.

height and width

An explicit size of the image, which is used by the progressive-image to determine the aspect ratio without fetching the image.

Compatibility

Requires ES2015 classes. IE11 and below not supported.

  • If targeting browsers that natively support ES2015, but not native Web Components:

    You will also need the Custom Elements V1 Polyfill.

    See caniuse.com for support on Custom Elements v1.

  • If targeting browsers that does not support ES2015:

    You might want to reconsider since you'll be better off not using Web Components in this case.

Licensing

MIT license