https://github.com/jenstornell/tiny-html-minifier
Minify HTML in PHP with just a single class
https://github.com/jenstornell/tiny-html-minifier
compress html minify minify-html shrink
Last synced: about 1 month ago
JSON representation
Minify HTML in PHP with just a single class
- Host: GitHub
- URL: https://github.com/jenstornell/tiny-html-minifier
- Owner: jenstornell
- License: mit
- Created: 2017-10-20T11:54:07.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-03T14:56:10.000Z (over 1 year ago)
- Last Synced: 2025-04-02T11:45:12.708Z (about 2 months ago)
- Topics: compress, html, minify, minify-html, shrink
- Language: PHP
- Size: 41 KB
- Stars: 184
- Watchers: 10
- Forks: 64
- Open Issues: 20
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license
Awesome Lists containing this project
README
# Tiny Html Minifier
  [](https://www.paypal.me/DevoneraAB)
[Changelog](changelog.md)
## In short
- A HTML minifier in PHP.
- It's really really fast.
- Only 1 file is required.
- Almost no regular expressions.
- Almost no options.## Details - What the minifier does
- Remove HTML comments.
- Remove slash in self closing elements. ` />` becomes `>`.
- Remove ` type="text/css"` and `type="text/javascript"` in `style` and `script` tags.
- Minimize elements within ``. It will not keep any whitespace (except inside `script`).
- Minimize elements within `` but keep spaces between tags to preserve inline data (optional).
- Minimize inline SVG files (which are a bunch of XML tags).
- Minimize Custom Elements. They look like this: `My content`.
- Skip `code`, `pre`, `script` and `textarea` from being minified.## Install & usage
### 1. Download
**ZIP**
Download `tiny-html-minifier.php` or the whole ZIP.
**Composer**
You can install it with Composer as well.
### 2. Add the code
```php
Tiny Html Minifier
Some text
with newlines
and some spaces
This text
should not
wrap on multiple lines
console.log('Script tags are not minified');
console.log('This is inside a script tag');```
### After
```html
Tiny Html Minifier
Some text
with newlines
and some spaces
This text
should not
wrap on multiple lines
console.log('Script tags are not minified');
console.log('This is inside a script tag');```
## Options
```php
false,
'disable_comments' => false,
]);
```### collapse_whitespace
#### Not collapsed
Spaces are preserved (except for most elements within ``). It's good when using the elements inline. This is the default.
```html
```
#### Collapsed
Spaces are collapsed. The text inside the element is still untouched. Set this value to `true` and you will save a few extra bytes.
```html
```
## Requirements
- PHP7+
## Disclaimer
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please [create a new issue](https://github.com/jenstornell/tiny-html-minifier/issues/new).
## License
[MIT](https://github.com/jenstornell/tiny-html-minifier/blob/master/license)
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.
## Donate
If you want to make a donation, you can do that by sending any amount https://www.paypal.me/DevoneraAB
## Credits
- [Jens Törnell](https://github.com/jenstornell)