Skip to content

Instantly share code, notes, and snippets.

@antoniofrignani
Created June 22, 2012 11:28
Show Gist options
  • Save antoniofrignani/2972206 to your computer and use it in GitHub Desktop.
Save antoniofrignani/2972206 to your computer and use it in GitHub Desktop.
[LARAVEL] Compress filter for Laravel
<?php
/*
|--------------------------------------------------------------------------
| Compress output before sending it to the browser
|--------------------------------------------------------------------------
|
| Removes all tabs and line breaks from the content before sending it to
| the browser.
|
| @example:
| Route::group(array('after' => 'compress'), function()
| {
| Route::controller('home');
| });
|
*/
Route::filter('compress', function( $response = null )
{
// Ensure we have a response, just in case someone sets the compress filter to run
// 'before' the request is sent to Laravel.
if ( $response ) {
$response->content = str_replace( array("\n","\t") , '' , $response->content );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment