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

astro-html-minifier-next

v2.1.0

Published

Minify Astro HTML assets using html-minifier-next!

Readme

astro-html-minifier-next

Minify Astro HTML assets using html-minifier-next!

  • Improves page speed - Reduces the size of HTML assets by removing everything unnecessary.
  • Highly configurable - All options from html-minifier-next are supported and can be customized.
  • Fast - Runs the minification of all assets with (limited) concurrency and Lightning CSS.

Version badge NPM downloads badge JSR score badge Minified size (gzip) badge

import { defineConfig } from "astro/config";
import htmlMinifier from "astro-html-minifier-next";

export default defineConfig({
  integrations: [
    htmlMinifier({
      /* My recommended html-minifier-next options: */
      caseSensitive: true,
      collapseBooleanAttributes: true,
      collapseInlineTagWhitespace: false,
      collapseWhitespace: true,
      conservativeCollapse: false,
      continueOnMinifyError: false,
      continueOnParseError: false,
      decodeEntities: true,
      html5: true,
      includeAutoGeneratedTags: true,
      keepClosingSlash: false,
      minifyCSS: true,
      minifyJS: true,
      minifyURLs: false,
      noNewlinesBeforeTagClose: false,
      preserveLineBreaks: false,
      preventAttributesEscaping: false,
      processConditionalComments: false,
      removeAttributeQuotes: false, // Technically they are optional and can greatly reduce size, but the HTML specification recommends always using quotes.
      removeComments: true,
      removeEmptyAttributes: true,
      removeEmptyElements: false,
      removeOptionalTags: false,
      removeRedundantAttributes: true,
      removeScriptTypeAttributes: true,
      removeStyleLinkTypeAttributes: true,
      removeTagWhitespace: false,
      sortAttributes: false,
      sortClassName: false,
      useShortDoctype: true,
    }),
  ],
});

Installation

Add the integration to your Astro project using the astro add command.
This will install the package and make the appropriate changes to your astro.config.mjs/astro.config.ts file in one step:

npx astro add astro-html-minifier-next

If you prefer to add the integration manually instead, complete the following two steps:

  1. Install the package to your project’s dependencies using your preferred package manager.
    If you’re using npm or aren’t sure, run this in the terminal:
    npm install --save-dev astro-html-minifier-next
    Or, if you're using Deno, run this in the terminal:
    deno add jsr:@jonasgeiler/astro-html-minifier-next
  2. Add the integration to your astro.config.mjs/astro.config.ts file:
    import { defineConfig } from "astro/config";
       
    // ADD THE FOLLOWING LINE:
    import htmlMinifier from "astro-html-minifier-next";
    
    export default defineConfig({
      // ...
       
      integrations: [
        // ...
       
        // ADD THE FOLLOWING LINE:
        htmlMinifier({ /* Your html-minifier-next options here. */ }),
      ],
    });

Usage

Once installed, the integration will automatically minify all HTML assets generated by Astro during the build process using the provided html-minifier-next options.

Options

You can find a quick reference of all available options in the html-minifier-next documentation.
You can also check out the JSDoc comments in the source code.

There is currently one additional option only specific to this Astro integration. See below.

Tip
To ensure consistent and wide browser support throughout your project, I recommend setting the targets property of the minifyCSS option to your project's Browserslist query. This configures Lightning CSS (the CSS minifier used by html-minifier-next) to properly optimize the CSS according to the browsers you want to support.

You can do this, by adding the following lines to your astro.config.mjs/astro.config.ts file:

import { defineConfig } from "astro/config";
import htmlMinifier from "astro-html-minifier-next";

// ADD THE FOLLOWING LINES:
import browserslist from "browserslist";
import { browserslistToTargets } from "lightningcss";

export default defineConfig({
  // ...

  integrations: [
    // ...

    htmlMinifier({
      // ...

      minifyCSS: {
        // ...

        // ADD THE FOLLOWING LINE:
        targets: browserslistToTargets(browserslist("defaults")),
      },
    }),
  ],
});

More information can be found in the Lightning CSS documentation.

alwaysWriteMinifiedHTML

This option is not passed to html-minifier-next. It only controls the behavior of this Astro integration.

By default, the integration only overwrites the original HTML assets if the minified HTML is smaller. However, there are cases where you might actually prefer the larger output due to special compatibility reasons or otherwise.
Setting this option to true causes the integration to always overwrite the HTML assets with their minified results, regardless of size.

Credits

This project wouldn't be possible without the awesome work of Juriy Zaytsev aka. @kangax (html-minifier), the Terser team (html-minifier-terser), and of course Jens Oliver Meiert aka. @j9t (html-minifier-next).