Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache mod_deflate not compressing json output

I've followed all the steps in multiple tutorials to enable mod_deflate in Apache but I'm still not seeing compression (in Fiddler) when I issue requests for json (via PHP script) to my local web server. Compression isn't necessary for my browser to localhost but my machine will be periodically exposed over a slow VPN so I would like to use it.

from httpd.conf:

LoadModule deflate_module modules/mod_deflate.so (not commented-out)

mod_deflate.so exists in Apache2/modules

PHP scripts immediately set the following header when run: header('Content-Type: application/json');

application/json exists in Apache2/conf/mime.types

And this is the relevant section from httpd.conf on the mime-types that should be compressed:

Alias /mapguide "C:/Program Files/OSGeo/MapGuide/Web/www/"
<Directory "C:/Program Files/OSGeo/MapGuide/Web/www/">
  AllowOverride All
  Options All -Indexes
  Order allow,deny
  Allow from all

...

  # Content compression
  AddType text/javascript js jgz
  AddOutputFilterByType DEFLATE text/javascript application/json text/html

  RewriteEngine on
  RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization},L]
</Directory>

When I issue a request to the server the request headers include Accept-Encoding: gzip, deflate, but the response comes back uncompressed. I have restarted Apache after every .conf change.

Any suggestions very welcome!

like image 429
tomfumb Avatar asked Jan 25 '12 20:01

tomfumb


People also ask

How do I enable compression in Apache?

Enable Compression for ApacheOpen your Apache virtual host file and enable gzip compression entries line by line. For example, to compress HTML, text, XML, CSS, and Javascript content types, add the following line to your virtual host or . htaccess file.

Can you gzip JSON response?

As text data, JSON data compresses nicely. That's why gzip is our first option to reduce the JSON data size. Moreover, it can be automatically applied in HTTP, the common protocol for sending and receiving JSON.

How do you check gzip compression is enabled or not?

Double click on the file and select headers. Under 'Response headers' you are looking for the 'Connection-Encoding' field, it will say gzip if it is enabled. NOTE: By default, Deflate is enabled on all of our servers.

What does mod_ deflate do?

The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.


1 Answers

Wild guess here... maybe add as a new row in the config:

AddOutputFilter DEFLATE php

or add

application/x-httpd-php

to the end of your exising AddOutputFilterByType list.

like image 107
Alex Howansky Avatar answered Sep 27 '22 22:09

Alex Howansky