Installations
npm install rehype-sort-attribute-values
Releases
7.0.1
Published on 27 Sept 2024
rehype-minify-whitespace@6.0.1
Published on 17 Sept 2024
hast-util-minify-whitespace@1.0.0
Published on 17 Sept 2024
rehype-remove-comments@6.1.0
Published on 17 Sept 2024
html-enumerated-attributes@1.1.0
Published on 01 Nov 2023
7.0.0
Published on 30 Aug 2023
Developer
Developer Guide
Module System
ESM
Min. Node Version
Typescript Support
Yes
Node Version
22.7.0
NPM Version
10.8.3
Statistics
90 Stars
249 Commits
16 Forks
9 Watching
1 Branches
13 Contributors
Updated on 29 Sept 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
9,914,491
Last day
-2.4%
13,057
Compared to previous day
Last week
3.6%
77,681
Compared to previous week
Last month
0.1%
327,531
Compared to previous month
Last year
34.7%
3,029,695
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
rehype plugins to minify HTML.
Contents
What is this?
This GitHub repository is a monorepo that contains a couple utilities, ±30 plugins, and a preset with good and safe default, to minify HTML:
In
1<!doctype html> 2<html lang="en-GB"> 3 <head> 4 <meta charset="utf-8"> 5 <meta http-equiv="content-language" content="en-US"> 6 <script src="index.js" type="text/javascript" language="javascript"> 7 alert(true); 8 </script> 9 <link rel="stylesheet" href="index.css" type="text/css"> 10 <title>Foo & bar</title> 11 </head> 12 <body> 13 <h1 class="foo foo">bar bar</h1> 14 <p id="alfred" id="alfred"> <strong>foo</strong> <em>bar</em> </p> 15 <button type="BUTTON" onclick="javascript:return false">Alpha</button> 16 </body> 17</html>
Out
1<!doctypehtml><html lang=en><meta charset=utf8><script src=index.js></script><link href=index.css rel=stylesheet><title>Foo & bar</title><h1 class=foo>bar bar</h1><p id=alfred><strong>foo</strong> <em>bar</em></p><button onclick=return!1 type=button>Alpha</button>
When should I use this?
This project is useful when you want to improve the size of HTML documents. It’s particularly useful when you’re already using rehype (and remark?) to process HTML.
Presets
Presets are combinations of plugins. One preset is maintained here:
rehype-preset-minify
— preset to minify and mangle HTML
Plugins
The following plugins maintained here are included in the above preset.
rehype-minify-attribute-whitespace
rehype-minify-css-style
rehype-minify-enumerated-attribute
rehype-minify-event-handler
rehype-minify-javascript-script
rehype-minify-javascript-url
rehype-minify-json-script
rehype-minify-language
rehype-minify-media-attribute
rehype-minify-meta-color
rehype-minify-meta-content
rehype-minify-style-attribute
rehype-minify-whitespace
rehype-normalize-attribute-value-case
rehype-remove-comments
rehype-remove-duplicate-attribute-values
rehype-remove-empty-attribute
rehype-remove-external-script-content
rehype-remove-meta-http-equiv
rehype-remove-script-type-javascript
rehype-remove-style-type-css
rehype-sort-attribute-values
rehype-sort-attributes
The following plugins are not included in the preset as they are potentially dangerous, can make sites slower in certain cases, or need extra configuration. Read their readmes before using:
rehype-concat-css-style
rehype-concat-javascript
rehype-css-to-top
rehype-javascript-to-bottom
rehype-minify-url
rehype-prevent-favicon-request
Also: pass allowDangerousCharacters
to rehype-stringify
if you trust your content.
Benchmark
Here’s a benchmark comparing the results from html-minifier
and rehype-minify
.
To summarize: differences are negligible, in fact, minifying HTML doesn’t matter
much.
What does matter is using good compressions, such as gzip.
Note: html-minifier
sometimes crashes, such as on amazon.
name | raw | gzip | ||||
---|---|---|---|---|---|---|
original | rehype-minify | html-minifier | original | rehype-minify | html-minifier | |
amazon | 567.85KB | 5.71% | 💥 | 128.65KB | 5.07% | 💥 |
bbc | 531.54KB | 4.70% | 4.58% | 58.09KB | 1.85% | 1.96% |
bootstrap | 33.96KB | 22.36% | 22.82% | 8.12KB | 5.17% | 5.36% |
compat-table | 8.67MB | 16.34% | 16.74% | 275.06KB | 8.26% | 10.06% |
ecmascript | 6.62MB | 10.86% | 11.56% | 789.66KB | 6.39% | 6.60% |
eloquent | 80.08KB | 6.43% | 6.45% | 19.13KB | 1.25% | 1.26% |
github | 233.14KB | 13.39% | 14.51% | 38.86KB | 7.48% | 7.91% |
253.98KB | 3.13% | 3.20% | 80.56KB | 3.64% | 3.63% | |
guardian | 765.54KB | 6.75% | 8.71% | 112.21KB | 3.96% | 4.38% |
html | 12.72MB | 3.15% | 3.19% | 1.85MB | 5.49% | 5.58% |
120.77KB | 32.29% | 32.34% | 14.4KB | 13.99% | 13.91% | |
microsoft | 174.26KB | 22.44% | 34.12% | 26.45KB | 12.96% | 15.45% |
nbc | 1.64MB | 5.94% | 6.28% | 221.08KB | 1.86% | 1.92% |
npm | 27.98KB | 3.03% | 2.61% | 8.28KB | 2.22% | 2.01% |
nytimes | 822.38KB | 11.80% | 11.80% | 137.47KB | 2.71% | 2.72% |
slack | 205.45KB | 4.76% | 4.55% | 49.63KB | 2.06% | 1.98% |
stackoverflow | 169.8KB | 18.64% | 19.10% | 45.4KB | 6.42% | 6.67% |
vice | 337.93KB | 3.48% | 3.22% | 92.58KB | 2.61% | 2.52% |
wikipedia | 768.18KB | 6.08% | 6.76% | 144KB | 1.58% | 1.77% |
total | 34.63MB | 31.9MB | 31.83MB | 4.05MB | 3.85MB | 3.85MB |
Huge differences in results are suspicious and may point to bugs.
💥 — Crash.
Security
Use of rehype-preset-minify
is safe by default if the tree is already safe.
As rehype works on HTML and improper use of HTML can open you up to a
cross-site scripting (XSS) attack, use of rehype can also be unsafe.
Use rehype-sanitize
to make the tree safe.
To further optimize the result disregarding security, use the extra plugins
listed above and pass allowDangerousCharacters
to
rehype-stringify
.
Related
rehype-format
— format HTML
Contribute
See contributing.md
in rehypejs/.github
for ways
to get started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
License
MIT © Titus Wormer
No vulnerabilities found.
Reason
13 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/rehypejs/.github/security.md:1
- Info: Found linked content: github.com/rehypejs/.github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/rehypejs/.github/security.md:1
- Info: Found text in security policy: github.com/rehypejs/.github/security.md:1
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/bb.yml:1
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/bb.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/rehypejs/rehype-minify/bb.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:6: update your workflow using https://app.stepsecurity.io/secureworkflow/rehypejs/rehype-minify/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:7: update your workflow using https://app.stepsecurity.io/secureworkflow/rehypejs/rehype-minify/main.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/rehypejs/rehype-minify/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:11
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Score
5
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More