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

lazyload-transform

v0.1.0

Published

transform html to support the lazy loading of images clientside

Downloads

1

Readme

go-lazyload-transform

IN DEVELOPMENT

Node package written in Go to transform html to support the lazy loading of images clientside

To install:

npm install --save lazyload-transform
yarn add lazyload-transform

To use:

const { Render } = require('lazyload-transform');

const html = '<html><head></head><body><img src="my-image.jpg"></body></html>';
const transformedHtml = Render(html);
console.log(transformedHtml);
// -> <html><head></head><body><img src="" data-src="my-image.jpg" class="lazyload-transform"><script>/*ClientSide JS Here...*/</script></body></html>

Transformation

By default, lazyload-transform will do 2 things:

  1. For all img tags, move the value of src to data-src
  2. For all html tags with an inline style attribute, move the first url to data-background-image and replace with a single pixel

Options to control behavior will be in the next release.

Benchmark

To compare to cheerio, run node ./benchmark/cheerio. This benchmark's cheerio implementation is a direct implementation of the functionality written in Go, following best practices from the cheerio documentation.

On a Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz this library is roughly 9-10x faster at parsing and manipulating 1494 lines of html.

LazyLoad Completed In: 7ms
Cheerio Completed In: 70ms

Development

Requires libxml2.

To test the go library run go test lazyload.go lazyload_test.go. To test the node wrapper run npm test. Node wrapper should always be tested after updating go library.

To generate lazyload.h and lazyload.a required for the node binding, run go build -buildmode=c-archive -o lazyload.a lazyload.go followed by node-gyp build to update the bindings.