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

hypercrush

v1.0.21

Published

Crushes HTML or SVG code.

Readme

npm

HyperCrush

Crushes HTML or SVG code. Code can be raw markup, or it can be Javascript that happens to contain quoted markup within. It should be used in conjunction with your html-minifier and your JS minifier/terser. This module doesn't do everything, it just squeezes a bit more out.

Why? Standard minifiers don't quite finesse like this!

Input:

<div id="myId" class="big blue" data-val="0.2"> Some <em> "text" here </em> </div>

Output:

<div id=myId class="big blue"data-val=.2>Some <em>"text" here</em></div>

👉 NOTE THE SAVINGS!!! ✔️

Gotcha: Now you can't rely on whitespace between tags for styling.

🔥 Try an online demo

(If you'd like to optimize and deduplicate multiple SVG files see JCrush SVG)

Stand-alone usage

See online demo link above, or download project zip file and open index.html to use the GUI.

Installation

This is a Node.JS module available from the Node Package Manager (NPM).

https://www.npmjs.com/package/hypercrush

Here's the command to download and install from NPM:

npm install hypercrush -S

or with Yarn:

yarn add hypercrush

Usage

Gulp Integration

In your gulpfile.mjs, use HyperCrush as a Gulp plugin:

Step 1: Import HyperCrush

import hypercrush from 'hypercrush';

Step 2: Add HyperCrush to your minification tasks

For Javascript that contains HTML in strings, add the default pass BEFORE your terser/minifier, and a whitespace pass AFTER like so:


    .pipe(hypercrush())
    .pipe(terser({ ecma: 7, mangle: { toplevel: true } }))
    .pipe(hypercrush('whitespace'))

For plain HTML, add an 'all` pass AFTER your minifier:


    .pipe(htmlmin({ collapseWhitespace: true }))
    .pipe(hypercrush('all'))

For SVG do an svg pass:

gulp.task('svg', function () {
  return gulp.src('./src/img/svg/*.svg')
    .pipe(hypercrush('svg'))
    .pipe(gulp.dest('./img/svg'));
});

Note: The SVG code will now only work embeded into the HTML DOM, not in an IMG tag or as a stand-alone file.

mode Parameter

The mode parameter controls the optimizations applied to the input files. It can be set to 'default', 'whitespace', or 'all'. There is also a bonus 'svg' mode available.

Available Modes

default (or omitted)

  • Removes leading zero from decimal numbers in attributes (0.5.5).
  • Eliminates unnecessary spaces between tags (> <><). Gotcha: Can't rely on whitespace between tags for styling!
  • Removes spaces before > in tags.
  • Strips unnecessary quotes from attribute values when safe (class="foo"class=foo).
  • Removes unnecessary spaces between attributes.
  • Removes extra spaces at the end of self-closing tags.

whitespace

  • Collapses multiple spaces into a single space.
  • Trims leading and trailing spaces.

all

  • Includes all optimizations from whitespace and default.

svg

  • Specific optimizations for extracting the SVG tag, stripping some attrs, and crushing the markup. Not a general-purpose SVG crusher, because the file won't work as normal and must be embeded in a HTML DOM.

Note

For more Javascript code compression check out JCrush. For CSS compression check out Gulp JCrush CSS.


Contributing

https://github.com/braksator/hypercrush

In lieu of a formal style guide, take care to maintain the existing coding style.