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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gulp-embed-lqip-as-background

v0.0.12

Published

Gulp LQIP small image placeholder generator plugin

Readme

Gulp LQIP small image placeholder generator plugin

npm version

Gulp plugin which generates HTML image placeholders using lqip technique and allows to embed them into the image background to get rid of client-side javascript.

It parses your (passed on input) HTML files to find images and adds a data-src attribute to them which contains their Base64 representation.

(LQIP stands for "Low-quality image placeholders" technique to provide already prepared small resource-effective image previews.)

This plugin does the same as Johann Servoire's gulp-image-lqip, but doesn't require JS on the client side -- it embeds a downscaled image into an image's style background (as an svg object) and sets loading=lazy attribute to allow the browser to control the images loading.

In case if you specify the dataSrcAttr options parameter, then it'll behave in original way: by storing the downscaled preview in the specified attribute instead of style:background object.

Other improvements are:

  • This plugin returns relevant vinyl streams and allow further processing of the stream. It means that now you must to handle the resulting streams (at least to write them into the destination).
  • It automatically sets the width, height and loading=lazy attributes for the processed images.
  • It doesn't try to prettify the results. So, you should care about that by yourself (take a look at the gulp-html-prettify plugin).

(Probably it's possible to improve the solution using scroll events intersection observer if you don't trust the browser's loading algorithm.)

Version info (auto-generated)

  • Project info: gulp-embed-lqip-as-background v.0.0.12 / 2025.05.04 19:21:36 +0300

Resources:

  • The project's repository: https://github.com/lilliputten/gulp-embed-lqip-as-background

You can see the real-case usage example in my other project:

Demos (see by a browser in a cloned repo):

  • Test result for test/test.html: [test/demo-test.html]test/demo-test.htmll). (See 'Example case' section below.)
  • Original plugin test (uses data-src attribute and in-page js code & styles): test/demo-data-src-test.html.

Install

npm install --save-dev gulp-embed-lqip-as-background

or

pnpm i -D gulp-embed-lqip-as-background

...etc...

Usage

const gulp = require('gulp');
const gulpEmbedLqipAsBackground = require('gulp-embed-lqip-as-background');

gulp.task('default', () => {
  return gulp
    .src(['*.html'])
    .pipe(
      gulpEmbedLqipAsBackground({
        // It requires an absolute path of the image's root (website root in your project).
        // This argument is only required.
        rootPath: __dirname,
        // The following arguments are optional, default values are displayed. See the options' reference below.
        // dataSrcAttr: 'data-src', // Specify to produce old-way `data-src` attribute (required extra js code & styles, see example in [test/demo-data-src-test.html](test/demo-data-src-test.html)).
        // lazyLoadClass: 'lazy-load',
        // srcAttr: 'src',
        // scaleFactorAttr: 'data-scale-factor',
        // scaleFactor: 10,
        // validFileExtensions: ['.html', '.htm'],
      }),
    )
    .pipe(gulp.dest('.'));
});

Supported files

Currently ['jpeg', 'jpg', 'png', 'gif'] files are supported.

No transparency is supported.

The images with a generated background:style svg objects mostly should have display: inline-block css rule to be displayed correctly (see bootstrap classes figure or v5's inline-block).

Example case

A tag in the source file (test/test.html):

<img src="img/csb.jpg" class="img-fluid lazy-load figure" data-scale-factor="5" />

Generated code (test/demo-test.html):

<img
  src="img/csb.jpg"
  class="img-fluid lazy-load figure"
  data-scale-factor="5"
  loading="lazy"
  style="background-size: cover; background-image: url(&quot;data:image/svg+xml;charset=utf-8,%3Csvg
    xmlns='http%3A//www.w3.org/2000/svg' xmlns%3Axlink='http%3A//www.w3.org/1999/xlink'
    viewBox='0 0 600 599'%3E%3Cfilter id='b' color-interpolation-filters='sRGB'%3E%3CfeGaussianBlur
    stdDeviation='.5'%3E%3C/feGaussianBlur%3E%3CfeComponentTransfer%3E%3CfeFuncA type='discrete'
    tableValues='1 1'%3E%3C/feFuncA%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Cimage
    filter='url(%23b)' preserveAspectRatio='none' height='100%25' width='100%25'
    xlink%3Ahref='data%3Aimage/jpeg;base64,/9j/---A LONG BASE64 ENCOED STRING IS COMING HERE---//2Q=='%3E%3C/image%3E%3C/svg%3E&quot;);"
  width="600"
  height="599"
/>

API

gulpEmbedLqipAsBackground(options)

options

Type: Object

rootPath
  • Type: string
  • Required

Define the rootPath for the images (probably that's the website root), it must be an absolute path.

lazyLoadClass
  • Type: string
  • Default: "lazy-load"

Image class to detect if this element should be processed. Don't check the class if empty.

srcAttr
  • Type: string
  • Default: "src"

Source attribute name. Should be relative (to the rootPath) path. Would be fetched from the data-src-attr-name of the node. Also the following attributes will be checked: data-src, data-lazy, data-lazy-src. Default: 'src'.

dataSrcAttr
  • Type: string
  • Default: ""

Data source attribute name to additionally store the scaled image base64 content, eg 'data-src'. Default: empty (don't store). Specify to produce old-way attributes (see an example in the test folder).

scaleFactorAttr
  • Type: string
  • Default: "data-scale-factor"

Downscale ratio attribute name to fetch the value from specific element. It'll override a value form the global scaleFactor attribute (see below). Default value: 'data-scale-factor'.

scaleFactor
  • Type: number
  • Default: 10

Downscale image ratio. Default value: 10.

validFileExtensions
  • Type: string[]
  • Default: ['.html', '.htm']

Valid source file extensions.

Thanks

License

MIT © Lilliputten & Noble