Last active
August 29, 2015 14:18
-
-
Save allaniftrue/1bcd99483b8e40156f6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php namespace App\Http\Middleware; | |
| use Closure; | |
| class AfterMiddleware{ | |
| /** | |
| * Handle an outgoing request. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param \Closure $next | |
| * @return mixed | |
| */ | |
| public function handle($request, Closure $next) | |
| { | |
| $response = $next($request); | |
| $filters = array( | |
| //Remove HTML comments except IE conditions | |
| '/<!--(?!\s*(?:\[if [^\]]+]|<!|>))(?:(?!-->).)*-->/s' => '', | |
| // Remove comments in the form /* */ | |
| '/(?<!\S)\/\/\s*[^\r\n]*/' => '', | |
| // Shorten multiple white spaces | |
| '/\s{2,}/' => '', | |
| // Collapse new lines | |
| '/(\r?\n)/' => '' | |
| ); | |
| $response = preg_replace(array_keys($filters), array_values($filters), $response); | |
| return $response; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php namespace App\Http; | |
| use Illuminate\Foundation\Http\Kernel as HttpKernel; | |
| class Kernel extends HttpKernel { | |
| /** | |
| * The application's global HTTP middleware stack. | |
| * | |
| * @var array | |
| */ | |
| protected $middleware = [ | |
| 'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode', | |
| 'Illuminate\Cookie\Middleware\EncryptCookies', | |
| 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', | |
| 'Illuminate\Session\Middleware\StartSession', | |
| 'Illuminate\View\Middleware\ShareErrorsFromSession', | |
| 'App\Http\Middleware\VerifyCsrfToken', | |
| ]; | |
| /** | |
| * The application's route middleware. | |
| * | |
| * @var array | |
| */ | |
| protected $routeMiddleware = [ | |
| 'auth' => 'App\Http\Middleware\Authenticate', | |
| 'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth', | |
| 'guest' => 'App\Http\Middleware\RedirectIfAuthenticated', | |
| 'minify' => 'App\Http\Middleware\AfterMiddleware' | |
| ]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| Route::group(['middleware' => 'minify'], function() | |
| { | |
| Route::get('/', 'BlogController@index'); | |
| Route::get('about', 'AboutController@index'); | |
| Route::get('projects', 'ProjectsController@index'); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment