├── .gitignore
├── src
├── config
│ └── config.php
└── Fitztrev
│ └── LaravelHtmlMinify
│ ├── LaravelHtmlMinifyServiceProvider.php
│ └── LaravelHtmlMinifyCompiler.php
├── .travis.yml
├── composer.json
├── phpunit.xml
├── LICENSE
├── README.md
└── tests
└── BaseMinifyTest.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | composer.phar
3 | composer.lock
4 | .DS_Store
5 |
6 | report
7 |
--------------------------------------------------------------------------------
/src/config/config.php:
--------------------------------------------------------------------------------
1 | true,
5 |
6 | // If you are using a javascript framework that conflicts
7 | // with Blade's tags, you can change them here
8 | 'blade' => array(
9 | 'contentTags' => array('{{', '}}'),
10 | 'escapedContentTags' => array('{{{', '}}}')
11 | )
12 |
13 | );
14 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 5.3
5 | - 5.4
6 | - 5.5
7 |
8 | before_install:
9 | - wget http://cs.sensiolabs.org/get/php-cs-fixer.phar
10 |
11 | before_script:
12 | - composer self-update
13 | - composer install --dev
14 |
15 | script:
16 | - phpunit
17 | - output=$(php php-cs-fixer.phar fix -v --dry-run --level=psr2 .); if [[ $output ]]; then while read -r line; do echo -e "\e[00;31m$line\e[00m"; done <<< "$output"; false; fi;
18 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fitztrev/laravel-html-minify",
3 | "description": "Minifies the HTML output of Laravel 4 applications",
4 | "keywords": ["laravel", "l4", "html", "optimization", "performance", "compress", "minify", "minifier", "blade"],
5 | "homepage": "https://github.com/fitztrev/laravel-html-minify",
6 | "license": "MIT",
7 | "authors": [
8 | {
9 | "name": "Trevor Fitzgerald",
10 | "email": "fitztrev@gmail.com"
11 | }
12 | ],
13 | "require": {
14 | "illuminate/view": "4.x"
15 | },
16 | "require-dev": {
17 | "mockery/mockery": "dev-master",
18 | "phpunit/phpunit": "3.7.*",
19 | "phpunit/php-code-coverage": ">=1.2.10,<1.3.0"
20 | },
21 | "autoload": {
22 | "psr-0": {
23 | "Fitztrev\\LaravelHtmlMinify": "src/"
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
15 | ./tests/
16 |
17 |
18 |
19 |
20 |
21 | src/Fitztrev/LaravelHtmlMinify/LaravelHtmlMinifyCompiler.php
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2013 Trevor Fitzgerald
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/src/Fitztrev/LaravelHtmlMinify/LaravelHtmlMinifyServiceProvider.php:
--------------------------------------------------------------------------------
1 | package('fitztrev/laravel-html-minify');
23 | }
24 |
25 | /**
26 | * Register the service provider.
27 | *
28 | * @return void
29 | */
30 | public function register()
31 | {
32 | $app = $this->app;
33 | $app->view->getEngineResolver()->register(
34 | 'blade.php',
35 | function () use ($app) {
36 | $cachePath = storage_path() . '/views';
37 | $compiler = new LaravelHtmlMinifyCompiler(
38 | $app->make('config')->get('laravel-html-minify::config'),
39 | $app['files'],
40 | $cachePath
41 | );
42 |
43 | return new CompilerEngine($compiler);
44 | }
45 | );
46 | $app->view->addExtension('blade.php', 'blade.php');
47 | }
48 |
49 | /**
50 | * Get the services provided by the provider.
51 | *
52 | * @return array
53 | */
54 | public function provides()
55 | {
56 | return array();
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## UPDATE for Laravel 5/5.1+
2 |
3 | Read my preferred way of minifying HTML in Laravel 5/5.1+ apps here: [Using Gulp to Minify Laravel Blade Templates](https://github.com/fitztrev/laravel-html-minify/wiki/Laravel-5---5.1-HTML-Minifying)
4 |
5 | ---
6 |
7 | # Laravel HTML Minify
8 |
9 | ### For Laravel 4 - See [here](https://github.com/fitztrev/laravel-html-minify/wiki/Laravel-5---5.1-HTML-Minifying) for L5+
10 |
11 | [](https://travis-ci.org/fitztrev/laravel-html-minify)
12 | [](https://packagist.org/packages/fitztrev/laravel-html-minify)
13 |
14 | ## About
15 |
16 | This package compresses the HTML output from your Laravel 4 application, seamlessly reducing the overall response size of your pages.
17 |
18 | 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.
19 |
20 | ## Why?
21 |
22 | Even with gzip enabled, there is still an improvement in the response size for HTML content-type documents.
23 |
24 | Test Page | w/o Gzip | w/ Gzip | w/ Gzip + Laravel HTML Minify
25 | --- | ---: | ---: | :---:
26 | **#1** | 8,039 bytes | 1,944 bytes | **1,836 bytes** (5.6% improvement)
27 | **#2** | 377,867 bytes | 5,247 bytes | **4,314 bytes** (17.8% improvement)
28 |
29 | ## Installation
30 |
31 | 1. Add `"fitztrev/laravel-html-minify": "1.*"` to **composer.json**.
32 | 2. Run `composer update`
33 | 3. Add `Fitztrev\LaravelHtmlMinify\LaravelHtmlMinifyServiceProvider` to the list of providers in **app/config/app.php**.
34 | 4. **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 {} \;`
35 |
36 | ## Config
37 |
38 | Optionally, you can choose to customize how the minifier functions for different environments. Publish the configuration file and edit accordingly.
39 |
40 | $ php artisan config:publish fitztrev/laravel-html-minify
41 |
42 | ### Options
43 |
44 | - **`enabled`** - *boolean*, default **true**
45 |
46 | If you are using a javascript framework that conflicts with Blade's tags, you can change them.
47 |
48 | - **`blade.contentTags`** - *array*, default `{{` and `}}`
49 | - **`blade.escapedContentTags`** - *array*, default `{{{` and `}}}`
50 |
51 | #### Skipping minification
52 |
53 | To prevent the minification of a view file, add `skipmin` somewhere in the view.
54 |
55 | ```
56 | {{-- skipmin --}}
57 |
58 | ```
59 |
--------------------------------------------------------------------------------
/src/Fitztrev/LaravelHtmlMinify/LaravelHtmlMinifyCompiler.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->setContentTags(
22 | $this->_config['blade']['contentTags'][0],
23 | $this->_config['blade']['contentTags'][1]
24 | );
25 |
26 | $this->setEscapedContentTags(
27 | $this->_config['blade']['escapedContentTags'][0],
28 | $this->_config['blade']['escapedContentTags'][1]
29 | );
30 |
31 | }
32 |
33 | /**
34 | * We'll only compress a view if none of the following conditions are met.
35 | * 1)
or