All Projects → jenstornell → Tiny Html Minifier

jenstornell / Tiny Html Minifier

Licence: mit
Minify HTML in PHP with just a single class

Projects that are alternatives of or similar to Tiny Html Minifier

csso-webpack-plugin
CSSO full restructuring minification files to serve your webpack bundles
Stars: ✭ 104 (-8.77%)
Mutual labels:  minify, compress
minifier
Middleware to minify Html, CSS and Javascript responses
Stars: ✭ 15 (-86.84%)
Mutual labels:  minify, compress
Babel Plugin Const Enum
Transform TypeScript `const` enums
Stars: ✭ 38 (-66.67%)
Mutual labels:  minify, compress
LaraOutPress
This is simply compress your final out of Larvel Application and serve to the browser.
Stars: ✭ 56 (-50.88%)
Mutual labels:  minify, compress
Html Minifier Terser
actively maintained fork of html-minifier - minify HTML, CSS and JS code using terser - supports ES6 code
Stars: ✭ 106 (-7.02%)
Mutual labels:  minify, compress
Instantbootstrap
Instant Bootstrap is a quick and easy way to start creating bootstrap themes using LESS, SASS, GRUNT, and BOWER.
Stars: ✭ 5 (-95.61%)
Mutual labels:  minify
Mybox
Easy tools of document, image, file, network, location, color, and media.
Stars: ✭ 45 (-60.53%)
Mutual labels:  compress
Leanify
lightweight lossless file minifier/optimizer
Stars: ✭ 694 (+508.77%)
Mutual labels:  minify
Uglifier
Ruby wrapper for UglifyJS JavaScript compressor.
Stars: ✭ 601 (+427.19%)
Mutual labels:  minify
Py7zr
7zip in python3 with ZStandard, PPMd, LZMA2, LZMA1, Delta, BCJ, BZip2, and Deflate compressions, and AES encryption.
Stars: ✭ 110 (-3.51%)
Mutual labels:  compress
Embed
Static content embedding for Golang
Stars: ✭ 94 (-17.54%)
Mutual labels:  minify
Simplifyify
A simplified Browserify and Watchify CLI
Stars: ✭ 37 (-67.54%)
Mutual labels:  minify
Maven Min Plugin
📦 Latke application JavaScript and CSS files compression.
Stars: ✭ 5 (-95.61%)
Mutual labels:  compress
Flask Htmlmin
Flask html response minifier
Stars: ✭ 66 (-42.11%)
Mutual labels:  minify
Gulp Htmlmin
Minify HTML
Stars: ✭ 720 (+531.58%)
Mutual labels:  minify
Uglifyjs Webpack Plugin
[deprecated] UglifyJS Plugin
Stars: ✭ 1,343 (+1078.07%)
Mutual labels:  minify
Lyo
📦 Node.js to browser - The easy way
Stars: ✭ 624 (+447.37%)
Mutual labels:  minify
Pg Minify
Minifies PostgreSQL scripts.
Stars: ✭ 37 (-67.54%)
Mutual labels:  minify
Compress.js
A simple JavaScript based client-side image compression algorithm
Stars: ✭ 86 (-24.56%)
Mutual labels:  compress
Gulp Tar
Create tarball from files
Stars: ✭ 28 (-75.44%)
Mutual labels:  compress

Tiny Html Minifier

Version 2.2 MIT license Donate

Changelog

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 <head></head>. It will not keep any whitespace (except inside script).
  • Minimize elements within <body></body> 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-element>My content</my-element>.
  • 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
require 'tiny-html-minifier.php';
echo TinyMinify::html($html);

Before / after

Before

<!doctype html>
<html lang="en">
<head>

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />

<link href="http://example.com/style.css" rel="stylesheet" />
<link rel="icon" href="http://example.com/favicon.png" />

<title>Tiny Html Minifier</title>

</head>
<body class="body">

<div class="main-wrap">
    <main>
        <textarea>
            Some text
            with newlines
            and some spaces
        </textarea>

        <div class="test">
            <p>This text</p>
            <p>should not</p>
            <p>wrap on multiple lines</p>
        </div>
    </main>
</div>
<script>
    console.log('Script tags are not minified');
    console.log('This is inside a script tag');
</script></body>
</html>

After

<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><link href="http://example.com/style.css" rel="stylesheet"><link rel="icon" href="http://example.com/favicon.png"><title>Tiny Html Minifier</title></head> <body class="body"><div class="main-wrap"> <main> <textarea>
            Some text
            with newlines
            and some spaces
        </textarea> <div class="test"> <p>This text</p> <p>should not</p> <p>wrap on multiple lines</p> </div> </main> </div> <script>
    console.log('Script tags are not minified');
    console.log('This is inside a script tag');
</script></body></html>

Options

<?php
require 'tiny-html-minifier.php';
echo TinyMinify::html($html, $options = [
    'collapse_whitespace' => false,
    'disable_comments' => false,
]);

collapse_whitespace

Not collapsed

Spaces are preserved (except for most elements within <head></head>). It's good when using the elements inline. This is the default.

<ul><li> <a href="#"> My link </a></li><li> <a href="#"> My link </a></li> </ul>

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.

<ul><li><a href="#">My link</a></li><li><a href="#">My link</a></li></ul>

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.

License

MIT

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].