Skip to content

Instantly share code, notes, and snippets.

@allaniftrue
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save allaniftrue/1bcd99483b8e40156f6d to your computer and use it in GitHub Desktop.

Select an option

Save allaniftrue/1bcd99483b8e40156f6d to your computer and use it in GitHub Desktop.
<?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;
}
}
<?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'
];
}
<?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