Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn on GZip for Laravel Ajax calls

I have a 2 views that make several ajax calls to some controllers. They return JSON results.

Google PageSpeed claimed I should enable it to achieve 89% compression (my page contacts the server every second, to update status).

I've enabled gzip through the .htaccess at the root the /public subdirectory - meaning all my static resources get compressed. But all my Ajax results do not. Where do I enable it? Do I add another .htaccess somewhere, or enable it in the PHP code itself?

like image 600
Traveling Tech Guy Avatar asked Jul 25 '13 16:07

Traveling Tech Guy


1 Answers

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE application/json
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
</IfModule>

This is what I use

like image 56
West55 Avatar answered Sep 23 '22 20:09

West55