Skip to content

Very, very simple HTML minifier with Laravel support

Notifications You must be signed in to change notification settings

nckg/laravel-minify-html

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTML minifier

Build Status Packagist Packagist codecov

Introduction

Very, very simple html minifier with Laravel 5.x support.

It minifies HTML by

  1. removing HTML comments except IE conditions
  2. removing comments
  3. shorten multiple white spaces
  4. removing whitespaces between HTML tags
  5. collapsing new lines

You should end up with a small size profit:

Uniminfied Minified
64.2KB 44.6KB

Code Samples

$input = "<a href="/foo" class="bar  moo        ">Hello World</a>";
$minifier = new Minifier();
$output = $minifier->html($string); // <a href="/foo" class="bar moo ">Hello World</a>

Installation

You can install the package via composer:

composer require nckg/laravel-minify-html

If you are using Laravel you can add the middleware to your middleware providers

// app/Http/Kernel.php
/**
 * The application's global HTTP middleware stack.
 *
 * @var array
 */
protected $middleware = [
    ...
    \Nckg\Minify\Middleware\MinifyResponse::class,
];

Testing

composer test

License

The MIT License (MIT).