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 🙏

© 2025 – Pkg Stats / Ryan Hefner

triggy

v1.0.6

Published

A webpack plugin for lazy loading JavaScript and CSS resources on user interaction

Readme

Triggy

npm version Build Status Release License: MIT Webpack Node.js

Triggy is a webpack plugin that loads the javascript and css files when user interaction happens like mouse move, scroll etc. It improves web page performance and boosts core web vitals.

Features

  • Automatic lazy load - it will automatically convert all the src attributes to data-src and href to data-href
  • Performance boost - it loads static resources only on user interaction
  • Webpack integration - very easy integration to webpack builder

Installation

npm install -D triggy

Note: The plugin needs to be installed as a dev dependency because it is only used at the time of build.

Usage

Basic Setup

Here is how to add the plguin to your webpack configuration-

const TriggyPlugin = require('triggy');

module.exports = {
  // ... your webpack config
  plugins: [
    new TriggyPlugin()
  ]
};

Advanced Configuration

const TriggyPlugin = require('triggy');

module.exports = {
  plugins: [
    new TriggyPlugin({
      enabled: true,           // Enable/disable the plugin
      timeout: 15000,         // Timeout in ms before automatic load static files (default: 10000)
      include: [/\.html$/],   // Files to process (default: HTML files)
      exclude: [/admin\.html/], // Files to exclude
      convertSrcToDataSrc: true, // Convert all the src attributes to data-src (default: true)
      lazyLoadFiles: ['app.js', 'utils.js', 'styles.css']  // Only lazy load the mentioned files
    })
  ]
};

How It Works

  1. Build Time: Triggy automatically-

    • Converts <script src="..."> to <script data-src="...">
    • Converts <link href="..."> to <link data-href="...">
    • Injects the lazy loading script at the end of your HTML
  2. Runtime: The injected script will-

    • monitor user interactions like mouse move, wheel, touch, click etc
    • load static resources when user interaction happens
    • fall back to automatic loading after 10 seconds (configurable)

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | enabled | boolean | true | Enable or disable the plugin | | timeout | number | 10000 | Timeout in milliseconds before automatic load static resources | | include | RegExp[] | [/\.html$/] | File patterns to process | | exclude | RegExp[] | [] | File patterns to exclude | | convertSrcToDataSrc | boolean | true | Convert all the src/href attributes to data-src/data-href | | lazyLoadFiles | string[] | [] | Specific files to lazy load (if empty, all .js/.css files are lazy loaded) |

Use Cases

When to disable convertSrcToDataSrc

Set convertSrcToDataSrc: false when:

  • You want to inject the lazy loading script without changing the src attributes
  • You're manually handling the data-src attributes in HTML
  • You want the lazy load functionality without attribute conversion
new TriggyPlugin({
  convertSrcToDataSrc: false // Only inject script, don't convert attributes
})

Selective File Loading

Use lazyLoadFiles to specify which files should lazy load:

new TriggyPlugin({
  lazyLoadFiles: ['app.js', 'utils.js', 'styles.css']
})

Behavior:

  • When you use lazyLoadFiles - it will lazy load only those specified files
  • When you dont use lazyLoadFiles - it will lazy load the .js and .css files

Example:

<script src="app.js"></script>        <!-- ✅ Will be lazy loaded -->
<script src="utils.js"></script>      <!-- ✅ Will be lazy loaded -->
<script src="critical.js"></script>   <!-- ❌ Will load normally -->
<link href="styles.css">              <!-- ✅ Will be lazy loaded -->
<link href="bootstrap.css">           <!-- ❌ Will load normally -->

Examples

Before (Original HTML)

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <script src="app.js"></script>
  <script src="vendor.js"></script>
</body>
</html>

After (Transformed HTML)

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" data-href="styles.css">
</head>
<body>
  <script data-src="app.js"></script>
  <script data-src="vendor.js"></script>
  <script>
    // Lazy loading script automatically injected here
  </script>
</body>
</html>

Integration Examples

React with Create React App

// webpack.config.js (eject or use CRACO)
const TriggyPlugin = require('triggy');

module.exports = {
  plugins: [
    new TriggyPlugin({
      timeout: 5000 // Load after 5 seconds
    })
  ]
};

Vue.js with Vue CLI

// vue.config.js
const TriggyPlugin = require('triggy');

module.exports = {
  configureWebpack: {
    plugins: [
      new TriggyPlugin()
    ]
  }
};

Next.js

// next.config.js
const TriggyPlugin = require('triggy');

module.exports = {
  webpack: (config) => {
    config.plugins.push(new TriggyPlugin());
    return config;
  }
};

Performance Benefits

  • Faster initial page load - these resources don't block page render
  • Better Core Web Vitals - it improves LCP and FCP scores
  • Reduced bandwidth usage - the resources load only when needed
  • Better user experience - the pages feel more responsive

Browser Support

  • Chrome 60+
  • Firefox 55+
  • Safari 12+
  • Edge 79+

License

MIT

Testing

The plugin includes wide test coverage:

npm test              # Run all tests
npm run test:watch    # Run tests in watch mode
npm run test:coverage # Run tests with coverage report
npm run ci            # Run full CI pipeline locally

CI/CD

This project uses GitHub Actions for continuous integration and deployment:

Workflows

  • CI Pipeline - Runs on every push and PR

    • Tests on Node.js 16.x, 18.x, and 20.x
    • Builds the project and examples
    • Runs security audits
    • Lints code with ESLint
  • Release Pipeline - Runs on version tags (v*)

    • Creates GitHub releases with changelog
    • Publishes to NPM automatically
    • Generates release notes from git commits

Contribution

Contributions are welcome! Please feel free to submit a Pull Request.

See CONTRIBUTION.md for detailed contribution manual.