GithubHelp home page GithubHelp logo

nckg / laravel-minify-html Goto Github PK

View Code? Open in Web Editor NEW
14.0 4.0 6.0 20 KB

Very, very simple HTML minifier with Laravel support

PHP 69.90% HTML 30.10%
html-minifier laravel middleware minifier php

laravel-minify-html's Introduction

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).

laravel-minify-html's People

Contributors

ibrunotome avatar mezhevikin avatar nckg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

laravel-minify-html's Issues

Problem with response()->download($path)

Hello!
Thank you for the lib.
I have problem with return response()->download($path).
How to disable MinifyResponse for this case?

Error:

The content cannot be set on a BinaryFileResponse instance.  (LogicException(code: 0): The content cannot be set on a BinaryFileResponse instance. at /var/www/examenpdd/vendor/symfony/http-foundation/BinaryFileResponse.php:323)
[stacktrace]
#0 /var/www/examenpdd/vendor/nckg/laravel-minify-html/src/Middleware/MinifyResponse.php(25): Symfony\\Component\\HttpFoundation\\BinaryFileResponse->setContent('')

pre/code

Hello,

pre and code are allways Compressed, have you a Workaround, to use the pre and code Tage without Removing Lines?

Inline elements sometimes need single white space

Filter "Remove white spaces between HTML tags" could have some exceptions like , as inline element. Removing spaces cause some view changes (no space between and you need add margin manually). I suggest add white list: span and button.

Tag the latest release

Could you tag the latest release so that we can pull that in through Composer without any workarounds? Specifically we need the fix introduced in commit a3b70ec.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.