├── tests └── .gitkeep ├── .gitignore ├── .travis.yml ├── src ├── config │ └── config.php └── Yocmen │ └── HtmlMinify │ ├── HtmlMinifyServiceProvider.php │ └── HtmlMinifyCompiler.php ├── composer.json ├── phpunit.xml └── README.md /tests/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | .idea -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | - hhvm 8 | 9 | before_script: 10 | - travis_retry composer self-update 11 | - travis_retry composer install --prefer-source --no-interaction --dev 12 | 13 | script: phpunit 14 | -------------------------------------------------------------------------------- /src/config/config.php: -------------------------------------------------------------------------------- 1 | true, 5 | 6 | // Turn on/off the comment stripping in the minified file 7 | 'comment_stripping' => true, 8 | 9 | // If you are using a javascript framework that conflicts 10 | // with Blade's tags, you can change them here 11 | 'blade' => [ 12 | 'rawTags' => ['{!!', '!!}'], 13 | 'contentTags' => ['{{', '}}'], 14 | 'escapedContentTags' => ['{{{', '}}}'] 15 | ] 16 | ]; 17 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yocmen/html-minify", 3 | "description": "Minifies the HTML output of Laravel 5 applications (Originally from https://github.com/fitztrev/laravel-html-minify)", 4 | "keywords": ["laravel", "l5", "html", "optimization", "performance", "compress", "minify", "minifier", "blade"], 5 | "homepage": "https://github.com/yocmen/html-minify", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Yocsel Mendoza", 10 | "email": "yocmen@gmail.com" 11 | }, 12 | { 13 | "name": "Trevor Fitzgerald", 14 | "email": "fitztrev@gmail.com" 15 | } 16 | ], 17 | "require": { 18 | "php": ">=5.4.0", 19 | "illuminate/support": "5.x" 20 | }, 21 | "autoload": { 22 | "psr-0": { 23 | "Yocmen\\HtmlMinify": "src/" 24 | } 25 | }, 26 | "minimum-stability": "stable" 27 | } 28 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | 19 | 20 | src/Yocmen/HtmlMinify/HtmlMinifyCompiler.php 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/Yocmen/HtmlMinify/HtmlMinifyServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 17 | __DIR__ . '/../../config/config.php' => config_path('htmlMinify.php'), 18 | ]); 19 | } 20 | 21 | /** 22 | * Register the service provider. 23 | * 24 | * @return void 25 | */ 26 | public function register() 27 | { 28 | $app = $this->app; 29 | $app->view->getEngineResolver()->register( 30 | 'blade', 31 | function () use ($app) { 32 | $cachePath = storage_path().'/framework/views'; 33 | $compiler = new HtmlMinifyCompiler( 34 | config('htmlMinify'), 35 | $app['files'], 36 | $cachePath 37 | ); 38 | 39 | return new CompilerEngine($compiler); 40 | } 41 | ); 42 | } 43 | 44 | /** 45 | * Get the services provided by the provider. 46 | * 47 | * @return array 48 | */ 49 | public function provides() 50 | { 51 | return []; 52 | } 53 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel 5 HTML Minify 2 | This package is originally from https://github.com/fitztrev/laravel-html-minify i just updated the package and made it compatible with laravel 5. 3 | 4 | ## About 5 | 6 | This package compresses the HTML output from your Laravel 5 application, seamlessly reducing the overall response size of your pages. 7 | 8 | Other scripts that I've seen will compress the HTML output on-the-fly for each request. Instead, this package extends the Blade compiler to save the compiled template files to disk in their compressed state, reducing the overhead for each request. 9 | 10 | ## Why? 11 | 12 | Even with gzip enabled, there is still an improvement in the response size for HTML content-type documents. 13 | 14 | Test Page | w/o Gzip | w/ Gzip | w/ Gzip + Laravel HTML Minify 15 | --- | ---: | ---: | :---: 16 | **#1** | 8,039 bytes | 1,944 bytes | **1,836 bytes** (5.6% improvement) 17 | **#2** | 377,867 bytes | 5,247 bytes | **4,314 bytes** (17.8% improvement) 18 | 19 | ## Installation 20 | 21 | 1. Add `"yocmen/html-minify": "2.*"` to **composer.json**. 22 | 2. Run `composer update` 23 | 3. Add `Yocmen\HtmlMinify\HtmlMinifyServiceProvider` to the list of providers in **config/app.php**. 24 | 4. Publish your config with `php artisan vendor:publish` command 25 | 5. **Important:** You won't see any changes until you edit your `*.blade.php` template files. Once Laravel detects a change, it will recompile them, which is when this package will go to work. To force all views to be recompiled, just run this command: `find . -name "*.blade.php" -exec touch {} \;` 26 | 27 | 28 | ### Options 29 | 30 | - **`enabled`** - *boolean*, default **true** 31 | - **`comment_stripping`** - *boolean*, default **true** 32 | 33 | If you are using a javascript framework that conflicts with Blade's tags, you can change them. 34 | 35 | - **`blade.rawTags`** - *array*, default `{!!` and `!!}` 36 | - **`blade.contentTags`** - *array*, default `{{` and `}}` 37 | - **`blade.escapedContentTags`** - *array*, default `{{{` and `}}}` 38 | 39 | #### Skipping minification 40 | 41 | To prevent the minification of a view file, add `skipmin` somewhere in the view. 42 | 43 | ``` 44 | {{-- skipmin --}} 45 | 46 | ``` 47 | -------------------------------------------------------------------------------- /src/Yocmen/HtmlMinify/HtmlMinifyCompiler.php: -------------------------------------------------------------------------------- 1 | _config = $config; 14 | 15 | // Add Minify to the list of compilers 16 | if ($this->_config['enabled'] === true) { 17 | $this->compilers[] = 'Minify'; 18 | } 19 | 20 | // Set Blade contentTags and escapedContentTags 21 | $this->setRawTags( 22 | $this->_config['blade']['rawTags'][0], 23 | $this->_config['blade']['rawTags'][1] 24 | ); 25 | 26 | $this->setContentTags( 27 | $this->_config['blade']['contentTags'][0], 28 | $this->_config['blade']['contentTags'][1] 29 | ); 30 | 31 | $this->setEscapedContentTags( 32 | $this->_config['blade']['escapedContentTags'][0], 33 | $this->_config['blade']['escapedContentTags'][1] 34 | ); 35 | 36 | } 37 | 38 | /** 39 | * We'll only compress a view if none of the following conditions are met. 40 | * 1)
 or