2017 © Pedro Peláez
 

library min-html

Compress HTML

image

axy/min-html

Compress HTML

  • Friday, January 12, 2018
  • by axy
  • Repository
  • 3 Watchers
  • 3 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

axy\min\html

Compress HTML., (*1)

Latest Stable Version Minimum PHP Version Build Status Coverage Status License, (*2)

  • The library does not require any dependencies.
  • Tested on PHP 5.4+, PHP 7, HHVM (on Linux), PHP 5.5 (on Windows).
  • Install: composer require axy/min-html.
  • License: MIT.

Compression

Simply removes the indentation at the beginning and end of lines. With some exceptions:, (*3)

  • Indents inside some tags (as <pre> and <textarea>) are relevant.
  • The content of some tags can be handled in a special way (compress for <script> and <style> for example).

Example

The source content:, (*4)

<head>
    <title>Test</title>
    <script>
    var x = 2 + 2;
    console.log(x);
    </script>
</head>
<body>
    <h1>Test</h1>
    <p>
    This is
    example
    of HTML compression.
    </p>
    <pre>
    Content of PRE
    is PRE
    </pre>
</body>

The compressed content:, (*5)

<head>
<title>Test</title>
<script>var x=2+2;console.log(x);</script>
</head>
<body>
<h1>Test</h1>
<p>
This is
example
of HTML compression.
</p>
<pre>
    Content of PRE
    is PRE
</pre>
</body>

API

The library defines the single public class axy\min\html\HTMLMinifier., (*6)

Methods:, (*7)

  • __construct(string $content [, array $tags])
  • run(void): string
  • getOriginContent(void): string
  • getCompressedContent(void): string
  • getTags(void): array

Static methods:, (*8)

  • compress(string $content [, array $tags]): string
  • compressFromFile(string $content [, array $tags]): string
  • compressFile(string $source, string $destination [, array $tags]): string
  • getDefaultsTags([array $tags]): array

Example

Using static:, (*9)

use axy\min\html\HTMLMinifier;

$source = 'index.html';
$destination = 'index.min.html';

HTMLMinifier::compressFile($source, $destination);

Without static:, (*10)

$min = new HTMLMinifier($content);
$min->run();
echo $min->getCompressedContent();

Tags

The optional array tags specifies how to handle content of the tags., (*11)

Defaults is, (*12)

[
    'pre' => true,
    'textarea' => true,
]

Argument $tags merges with the defaults., (*13)

TRUE - do not change. Or callback., (*14)

$tags = [
    'script' => function ($content) {
        return JSMinify::minify($content);
    },
    'textarea' => null, // Remove rule for TEXTAREA
    'style' => true, // Content of STYLE does not change
];

HTMLMinifier::compressFile($source, $destination, $tags);

The Versions

12/01 2018

dev-master

9999999-dev https://github.com/axypro/min-html

Compress HTML

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

html compress

08/12 2015

0.1.1

0.1.1.0 https://github.com/axypro/min-html

Compress HTML

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

html compress

24/10 2015

0.1.0

0.1.0.0 https://github.com/axypro/min-html

Compress HTML

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

html compress