Skip to content

Instantly share code, notes, and snippets.

@thewinterwind
Last active July 26, 2019 09:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thewinterwind/9728730 to your computer and use it in GitHub Desktop.
Save thewinterwind/9728730 to your computer and use it in GitHub Desktop.
How to gzip AJAX response with PHP (Laravel 4 flavor)
<?php
public function all()
{
if (Request::ajax()) {
$encoded_html = gzencode(Model::all(), 9);
header('Content-Length: ' . strlen($encoded_html));
header('Content-Encoding: gzip');
return $encoded_html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment