CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-html-minifier

Highly configurable, well-tested, JavaScript-based HTML minifier with extensive optimization options

86

1.17x
Overview
Eval results
Files

task.mdevals/scenario-9/

Attribute Cleanup Helper

A utility that trims HTML responses by cleaning up redundant or empty attributes while leaving tag structure and content untouched.

Capabilities

Only attribute tokens should change; tag order, inner text, and spacing between elements should remain as provided.

Remove empty and defaulted attributes

  • Strips empty attributes and default script/style type declarations without altering inner content ordering. For example, <script type="text/javascript" async="" src="/app.js"></script><link rel="stylesheet" type="text/css" href="/styles.css"> becomes <script async src=/app.js></script><link rel=stylesheet href=/styles.css>. @test

Collapse boolean attributes

  • Boolean attributes that repeat their name as a value (e.g., disabled="disabled") are reduced to the bare attribute while keeping non-boolean attributes intact. @test

Normalize attribute quoting

  • Removes unnecessary attribute quotes when safe but preserves quotes when values contain spaces or special characters so output like id=main and title="hero section" co-exist in the same node. @test

Implementation

@generates

API

export interface CleanupOptions {
  /**
   * When true, drops empty attribute declarations; defaults to true.
   */
  removeEmpty?: boolean;
  /**
   * When true, collapses boolean attributes to bare names; defaults to true.
   */
  collapseBooleans?: boolean;
  /**
   * When true, removes quotes when safe and keeps them when required; defaults to true.
   */
  trimQuotes?: boolean;
}

/**
 * Cleans HTML attribute usage while leaving tag structure and text content unchanged.
 * @param html Raw HTML string to process.
 * @param options Optional toggles controlling attribute cleanup behaviors.
 */
export function cleanAttributes(html: string, options?: CleanupOptions): string;

Dependencies { .dependencies }

html-minifier { .dependency }

Provides HTML minification primitives for attribute cleanup (empty attributes, redundant defaults, boolean collapsing, safe quote removal).

Install with Tessl CLI

npx tessl i tessl/npm-html-minifier

tile.json