html-minifier
Version, currently master branch1 version
- master branchlatestAug 9, 2021
github.com/sam0x17/html-minifier
A zero-dependency HTML/CSS/Javascript minifier for the Crystal language
Installation
# Add this to your shard.yml
dependencies:
html-minifier:
github: sam0x17/html-minifier
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
0.31.0- License
- MIT
- Author
- Sam Johnson
Dependencies
Runtime Dependencies
- duktape~> 1.0.0github: jessedoyle/duktape.cr
README
html-minifier
html-minifier embeds the widely-used html-minifier NPM package in an easy-to-use Crystal shard via duktape.cr, which provides a fast, embedded Javascript execution environment within Crystal.
html-minifier can be used to minify arbitrary HTML content, including Javascript and/or CSS.
Some features:
- minifies HTML and any embedded CSS/Javascript within the HTML
- no non-Crystal dependencies (no Node.js or NPM required)
- all html-minifier Javascript is baked into the shard, so you won't need to package any extra files with your app/tool/library
- doesn't embed an entire Node.js runtime (Javascript is executed via duktape.cr)
- simple, Crystal-based API (
HtmlMinifier.minify!("source code") - full support for html-minifier options via
HtmlMinifier.set_options - sane, one-size-fits-all options are included by default (unlike html-minifier on NPM)
Installation
-
Add the dependency to your
shard.yml:dependencies: html-minifier: github: sam0x17/html-minifier -
Run
shards install
Minification
require "html-minifier"
HtmlMinifier.minify!("<html> <body>minify me!</body></html>") # => "<html> <body>minify me!</body></html>"
HtmlMinifier.minify!("<style>body { background-color: black }</style>") # => "<style>body{background-color:#000}</style>"
HtmlMinifier.minify!("<script> alert('hello world');</script>") # => "<script>alert(\"hello world\")</script>"
Configuration
All options supported by html-minifier on NPM are supported by this shard. Options can be specified
by a JSON::Any object or by a JSON string, as shown below.
require "html-minifier"
HtmlMinifier.minify!("<html><!-- comment --></html>") # => "<html></html>"
HtmlMinifier.set_options("{\"removeComments\": false}")
HtmlMinifier.minify!("<html><!-- comment --></html>") # => "<html><!-- comment --></html>"
Note that user-specified options will override their respective default values. The default values for all options are shown below:
{
"caseSensitive": true,
"conservativeCollapse": true,
"minifyCSS": true,
"minifyJS": true,
"useShortDoctype": true,
"removeTagWhitespace": true,
"removeScriptTypeAttributes": true,
"removeComments": true,
"collapseWhitespace": true,
"collapseInlineTagWhitespace": true,
}
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Aug 9, 2021
- Crystal
0.31.0- Indexed
- yes
Dependents
Repository
github.com/sam0x17/html-minifier
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 14, 2026
- Synced
- Aug 14, 2026
- Versions
- 1