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

llm-html-compressor

v1.0.0

Published

An optimized HTML compressor for LLM context that removes white noise from HTML documents

Readme

llm-html-compressor

npm version License: MIT

A specialized HTML compressor designed to optimize HTML content for use as context with Large Language Models (LLMs). Removes unnecessary whitespace, comments, and other "noise" from HTML documents to make them more suitable for LLM processing while preserving semantically important content.

Installation

npm install llm-html-compressor
# or
yarn add llm-html-compressor

Why use llm-html-compressor?

When using HTML content as context for LLMs, unnecessary elements like whitespace, comments, and certain attributes can:

  1. Consume token quota without adding value
  2. Add noise that makes it harder for the LLM to focus on important content
  3. Increase the chance of context truncation

This library provides targeted optimizations specifically designed for LLM context usage, distinct from traditional HTML minifiers which focus on network transmission size.

Usage

Basic Usage

import { compress } from 'llm-html-compressor';

const html = `
<!DOCTYPE html>
<html>
  <!-- This is a comment -->
  <head>
    <title>Example</title>
    <style>
      body { font-family: Arial, sans-serif; }
    </style>
  </head>
  <body>
    <div class="container" id="main">
      <h1>Hello, World!</h1>
      <p style="color: blue; font-size: 16px;">This is an example.</p>
    </div>
    <script>
      console.log('Hello');
    </script>
  </body>
</html>
`;

const compressed = compress(html);
console.log(compressed);
// Output: <!DOCTYPE html><html><head><title>Example</title><style>body { font-family: Arial, sans-serif; }</style></head><body><div class="container" id="main"><h1>Hello, World!</h1><p style="color:blue;font-size:16px;">This is an example.</p></div><script>console.log('Hello');</script></body></html>

Advanced Usage with Custom Options

import { createCompressor } from 'llm-html-compressor';

const compressor = createCompressor({
  removeComments: true,
  collapseWhitespace: true,
  removeEmptyAttributes: true,
  removeStyleTags: true,
  removeScriptTags: true,
  preserveLineBreaks: false,
  removeDataAttributes: true,
  removeHiddenElements: true,
  minifyInlineCSS: true,
  removeClassAttributes: true,
  removeIdAttributes: false
});

const html = `... your HTML here ...`;
const compressed = compressor.compress(html);

API

Functions

compress(html: string): string

Compresses HTML using default options.

createCompressor(options?: Partial<CompressionOptions>): HtmlCompressor

Creates a compressor instance with custom options.

Classes

HtmlCompressor

The main compressor class that can be instantiated directly.

import { HtmlCompressor } from 'llm-html-compressor';

const compressor = new HtmlCompressor(options);
const result = compressor.compress(html);

CompressionOptions

| Option | Type | Default | Description | |--------|------|---------|-------------| | removeComments | boolean | true | Removes HTML comments | | collapseWhitespace | boolean | true | Collapses multiple whitespace characters into a single space | | removeEmptyAttributes | boolean | true | Removes attributes with empty values | | removeStyleTags | boolean | false | Removes <style> tags and their content | | removeScriptTags | boolean | false | Removes <script> tags and their content | | preserveLineBreaks | boolean | false | Preserves line breaks when collapsing whitespace | | removeDataAttributes | boolean | false | Removes data-* attributes | | removeHiddenElements | boolean | false | Removes elements with display:none or hidden attribute | | minifyInlineCSS | boolean | false | Minifies inline CSS in style attributes | | removeClassAttributes | boolean | false | Removes class attributes | | removeIdAttributes | boolean | false | Removes id attributes |

Use Cases

  • Preprocessing HTML for RAG (Retrieval-Augmented Generation) systems
  • Optimizing web page content for chatbots and assistants
  • Reducing token usage when working with HTML documentation
  • Making HTML content more digestible for code analysis with LLMs

License

MIT