Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A simple Middleware HTML minifier for Laravel

License

NotificationsYou must be signed in to change notification settings

FarshadGhanbari/laravel-HTMLMin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

Laravel HTMLMin is currently maintained byRaza Mehdi, and is a simple HTML minifier forLaravel 5. It utilises Mr Clay'sMinify package to minify entire responses, but can also minify blade at compile time. Feel free to check out thechange log,releases,license, andcontribution guidelines.

StyleCI StatusSoftware LicenseLatest Version

This package isn’t work on Laravel 5.6 version, for use in laravel 5.6 follow the tutorial :

Installation

Laravel HTMLMin requiresPHP 5.5+. supports all version of Laravel.

Configuration

Step 1: Create Custom Validation

$ php artisan make:middleware OptimizeMiddleware

After above run command you will find one file on bellow location and you have to write following code:

app/Http/Middleware/OptimizeMiddleware.php
<?php/*** (c) Farshad Ghanbari<eng.ghanbari2025@gmail.com>**/namespace App\Http\Middleware;use Closure;class OptimizeMiddleware{    /*** Handle an incoming request.* (c) Farshad Ghanbari<eng.ghanbari2025@gmail.com>* @param\Illuminate\Http\Request$request* @param\Closure$next* @return mixed*/    publicfunctionhandle($request, Closure$next)    {$response =$next($request);$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);        ini_set('zlib.output_compression','On');return$response;    }}

After successfully write logic of middleware then we have to register this middleware on kernel file. So let's simply add this way:

app/Http/Kernel.php
<?phpnamespace App\Http;use Illuminate\Foundation\Http\Kernel as HttpKernel;class Kernel extends HttpKernel{    /*** The application's global HTTP middleware stack.     *     * These middleware are run during every request to your application.     *     * @var array     */    protected $middleware = [        ....        \App\Http\Middleware\OptimizeMiddleware::class,    ];}

License

Laravel HTMLMin is licensed underThe MIT License (MIT).

About

A simple Middleware HTML minifier for Laravel

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp