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-7/

Attribute/Class Sorting Utility

A small utility that reorders attributes and class tokens in HTML markup to improve compression benefits while leaving all other content untouched.

Capabilities

Attribute ordering by frequency

  • Given markup with repeated attributes across elements, return HTML whose attributes are ordered from most common attribute name to least common within each element; ties fall back to alphabetical order and no attributes are dropped. @test

Class token ordering by frequency

  • Given markup with class lists sharing tokens across elements, return HTML whose class attribute values reorder tokens by descending token frequency across the document; ties are alphabetical and spacing is normalized to single spaces. @test

Isolated sorting (no extra minification)

  • When only attribute/class sorting is requested, preserve all other markup (text nodes, comments, inter-tag whitespace) aside from the reordered attributes/classes. @test

Toggleable behaviors

  • Options allow enabling or disabling attribute sorting and class-token sorting independently; disabling one leaves its original order untouched while the other still reorders. @test

Implementation

@generates

API

/**
 * Reorders HTML attributes and class tokens for compression-friendly layout.
 * @param {string} html - Raw HTML markup to process.
 * @param {{ sortAttributes?: boolean, sortClasses?: boolean }} [options] - Controls whether attribute and/or class token ordering is applied. Defaults to enabling both sorts.
 * @returns {string} Markup with requested sorting applied.
 */
export function reorderMarkup(html, options);

Dependencies { .dependencies }

html-minifier { .dependency }

Provides HTML minification with frequency-based attribute and class token sorting.

Install with Tessl CLI

npx tessl i tessl/npm-html-minifier

tile.json