smsmail
By:
smsmail

how to compress a json response with no file name

July 3, 2017 386 views
Apache Ubuntu 16.04

If I check my site it tells me that i need to compress https://distance2job.com/jm-ajax/get_listings/ .

I currently have this loaded in my apache2 config.

    <IfVersion < 2.4.4>
        <IfModule filter_module>
            # HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
            FilterDeclare   COMPRESS
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $text/html
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $text/css
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $text/plain
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $text/xml
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $text/x-component
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $application/javascript
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $application/json
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $application/xml
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $application/xhtml+xml
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $application/rss+xml
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $application/atom+xml
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $application/vnd.ms-fontobject
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $image/svg+xml
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $image/x-icon
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $application/x-font-ttf
            FilterProvider  COMPRESS    DEFLATE resp=Content-Type   $font/opentype
            FilterChain COMPRESS
            FilterProtocol  COMPRESS    DEFLATE change=yes;byteranges=no
        </IfModule>
    </IfVersion>

    <IfVersion >= 2.4.4>
        <IfModule filter_module>
            FilterDeclare   COMPRESS
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'text/html'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'text/css'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'text/plain'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'text/xml'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'text/x-component'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'application/javascript'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'application/json'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'application/xml'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'application/xhtml+xml'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'application/rss+xml'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'application/atom+xml'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'application/vnd.ms-fontobject'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'image/svg+xml'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'image/x-icon'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'application/x-font-ttf'"
            FilterProvider  COMPRESS    DEFLATE "%{Content_Type} = 'font/opentype'"
            FilterChain COMPRESS
            FilterProtocol  COMPRESS    DEFLATE change=yes;byteranges=no
        </IfModule>
    </IfVersion>

    <IfModule !mod_filter.c>
        # Legacy versions of Apache httpd
        AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
        AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
        AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
    </IfModule>

What am I missing to allow me to compress /get_listings/ ?

2 Answers

Hi @smsmail

I might be totally lost in Apache by now, but found some code in one of my old configs

<IfModule deflate_module>
  AddOutputFilterByType DEFLATE application/json application/javascript text/css text/html text/javascript text/plain text/xml
</IfModule>

And make sure that you have the module mod_deflate enabled in your apache2.conf.
I don't have any Apache installations running, but will setup one if this doesn't work for you.

I think that I already have that in the config and everything else but the one url is compressing fine.

Have another answer? Share your knowledge.