Question: In Laravel 4.0, I use the code below to compress the HTML laravel response outputs to browser, however it doesn't work in laravel 5.

```
App::after(function($request, $response)
{
    if($response instanceof Illuminate\Http\Response)
    {
        $buffer = $response->getContent();
        if(strpos($buffer,'<pre>') !== false)
        {
            $replace = array(
                '/<!--[^\[](.*?)[^\]]-->/s' => '',
                "/<\?php/"                  => '<?php ',
                "/\r/"                      => '',
                "/>\n</"                    => '><',
                "/>\s+\n</"                 => '><',
                "/>\n\s+</"                 => '><',
            );
        }
        else
        {
            $replace = array(
                '/<!--[^\[](.*?)[^\]]-->/s' => '',
                "/<\?php/"                  => '<?php ',
                "/\n([\S])/"                => '$1',
                "/\r/"                      => '',
                "/\n/"                      => '',
                "/\t/"                      => '',
                "/ +/"                      => ' ',
            );
        }
        $buffer = preg_replace(array_keys($replace), array_values($replace), $buffer);
        $response->setContent($buffer);
    }
});

```

Please how do i make this work in Laravel 5. 

OR

Please provide a better way of compressing HTML in laravel 5 if any.
Thanks in advance. 

NB: I don't wish to use any laravel package for compressing html, just need a simple code that does the work without killing performance.

Answer: 
I have created a webpack plugin to solve same purpose.[MinifyHtmlWebpackPlugin](https://www.npmjs.com/package/minify-html-webpack-plugin)

Install the plugin with npm:

```sh
$ npm install minify-html-webpack-plugin --save-dev

```

For Laravel Mix Users
=====================

Paste below snippets into mix.js file.

```js
    const MinifyHtmlWebpackPlugin = require('minify-html-webpack-plugin');
    const mix = require('laravel-mix');

    mix.webpackConfig({
        plugins: [
            new MinifyHtmlWebpackPlugin({
                src: './storage/framework/views',
                ignoreFileNameRegex: /\.(gitignore)$/,
                rules: {
                    collapseWhitespace: true,
                    removeAttributeQuotes: true,
                    removeComments: true,
                    minifyJS: true,
                }
            })
        ]
    });

```

It will minify all view files during the Webpack build.
This package is much better option in my opinion [renatomarinho/laravel-page-speed](https://github.com/renatomarinho/laravel-page-speed)