https://github.com/jlevy/tminify
Standalone, modern HTML/CSS/JS and Tailwind v4 minification for CLI and Python using terser
https://github.com/jlevy/tminify
Last synced: 9 months ago
JSON representation
Standalone, modern HTML/CSS/JS and Tailwind v4 minification for CLI and Python using terser
- Host: GitHub
- URL: https://github.com/jlevy/tminify
- Owner: jlevy
- License: mit
- Created: 2025-06-07T23:22:05.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-25T17:05:08.000Z (10 months ago)
- Last Synced: 2025-07-25T22:13:20.079Z (10 months ago)
- Language: Python
- Homepage:
- Size: 96.7 KB
- Stars: 2
- Watchers: 0
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tminify
This is a convenient CLI and Python lib wrapper for
[html-minifier-terser](https://github.com/terser/html-minifier-terser)
[Tailwind v4 CLI](https://tailwindcss.com/docs/installation/tailwind-cli)
## Installation
I recommend you [use uv](installation.md):
```shell
uv tool install --upgrade tminify
```
Run `--help` for details:
```shell
$ tminify --help
usage: tminify [-h] [--version] [--no_minify] [--preflight] [--tailwind] [--verbose] src_html dest_html
HTML minification with Tailwind CSS v4 compilation
positional arguments:
src_html Input HTML file.
dest_html Output HTML file.
options:
-h, --help show this help message and exit
--version show program's version number and exit
--no_minify Skip HTML minification (only compile Tailwind if present).
--preflight Enable Tailwind's preflight CSS reset (disabled by default to preserve custom styles).
--tailwind Force Tailwind CSS compilation even if CDN script is not present.
--verbose, -v Enable verbose logging.
CLI for HTML minification with Tailwind CSS v4 compilation.
This script can be used for general HTML minification (including inline CSS/JS) and/or
Tailwind CSS v4 compilation and inlining (replacing CDN script with compiled CSS).
Minification includes:
- HTML structure: whitespace removal, comment removal
- Inline CSS: all tags and style attributes are minified
- Inline JavaScript: all <script> tags are minified (not external JS files)
tminify v0.1.3.dev4+d976d28
```
## Minification of Static HTML/CSS/JavaScript Pages
The first use case for tminify is as a CLI or Python function to minify HTML, CSS, and
JavaScript using html-minifier-terser, the highly configurable, well-tested,
JavaScript-based HTML minifier.
It makes this minifier quick to install with uv.
You can then use it as a CLI tool or it can be added as a PyPI dependency to a project
and used as a minification library from Python.
It then internally handles (and caches) the Node dependencies.
Once it is installed, you can just use it on static files with a single command, with no
package.json or npm project setup!
Internally, it checks for an npm installation and uses that, raising an error if not
available.
Once it finds npm, it does its own internal `npm install` of required tools so
it’s self-contained.
The required npm packages are installed locally within the Python site-packages
directory.
## Tailwind v4 Compilation
In addition to general minification, tminify also compiles Tailwind CSS v4 standalone,
without other project config or setup.
You might think Tailwind v4 compilation would be as simple as a single CLI command, but
it seems like it’s not, since the modern Tailwind CLI seems developed around the use
case of a full hot-reloading JavaScript app setup.
This is fine if that’s the use case, but quite inconvenient if you don’t to set up a
package.json and other things and just want to compile and minify a static HTML page.
With Tailwind, simple zero-build page development is easy via the
[Play CDN](https://tailwindcss.com/docs/installation/play-cdn).
To do this, you put a tag like `<script
src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>` in your code.
However, that setup is not recommended by Tailwind for production use due to its poor
performance (scanning the whole page at load time to find Tailwind classes).
This tool lets you use any Play CDN link so you can “drop in” Tailwind on static web
pages during development.
Once you want to minify before publishing it, run tminify, and will detect the Tailwind
CDN script and compile and inline the production Tailwind CSS necessary for your page
(and then minify everything else, including HTML and JavaScript).
## Are There Alternatives?
Previously I had been using the [minify-html](https://github.com/wilsonzlin/minify-html)
(which has a convenient [Python package](https://pypi.org/project/minify-html/)) for
general minification.
It is great and fast.
But I found I kept running into
[issues](https://github.com/wilsonzlin/minify-html/issues/236) and in any case wanted
proper Tailwind v4 compilation, so switched to this of combining Tailwind compilation
with robust HTML/CSS/JS minification.
## Example Usage
Take a file you want to minimize.
Let’s put this file into `page.html`. Note we are using the Play CDN for simple
zero-build development:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test HTML</title>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<style>
/* Custom CSS that will be minified alongside Tailwind */
.custom-shadow {
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
Test Header
This is a test paragraph with some content.
Click Me
// This JavaScript should get minified
function testFunction() {
console.log('Hello from test function!');
alert('Button was clicked!');
return 'Some return value';
}
Test Header
This is a test paragraph with some content.
Click Mefunction testFunction(){return console.log("Hello from test function!"),alert("Button was clicked!"),"Some return value"}