0

We have a custom controller returning some json, this doesn't appear to be gzipped.

The response has: Content-Type: application/json, I've modified the root .htaccess to enable gzip but it doesn't seem to make any difference for the controller.

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE "application/atom+xml" \
                                "application/javascript" \
                                "application/json" \
                                "application/ld+json" \
                                "application/manifest+json" \
                                "application/rdf+xml" \
                                "application/rss+xml" \
                                "application/schema+json" \
                                "application/vnd.geo+json" \
                                "application/vnd.ms-fontobject" \
                                "application/x-font-ttf" \
                                "application/x-javascript" \
                                "application/x-web-app-manifest+json" \
                                "application/xhtml+xml" \
                                "application/xml" \
                                "font/eot" \
                                "font/opentype" \
                                "image/bmp" \
                                "image/svg+xml" \
                                "image/vnd.microsoft.icon" \
                                "image/x-icon" \
                                "text/cache-manifest" \
                                "text/css" \
                                "text/html" \
                                "text/javascript" \
                                "text/plain" \
                                "text/vcard" \
                                "text/vnd.rim.location.xloc" \
                                "text/vtt" \
                                "text/x-component" \
                                "text/x-cross-domain-policy" \
                                "text/xml"
  Header append Vary User-Agent env=!dont-vary

</IfModule>

It does make css/js gzipped so the mod_deflate seems to be enabled and working.

I would prefer to not need to modify the controller itself because on our dev/live site we have varnish + cdn and those already take care of gzipping it.

The controller is made in a pretty "core way" so I don't get why it's not working. Anyone have any ideas?

The first class is the controller that is been called from an ajax request in frontend using GET.

class Vendor_Elasticsearch_CatalogController extends Vendor_React_Controller_AbstractController {
    // ...
    protected function _sendResponse($response, $httpCode)
    {
        if (is_array($response)) {               
            $response = $result = json_encode($response, JSON_FORCE_OBJECT);
        }
        $this->getResponse()
            ->setHeader('Content-type', 'application/json')
            ->setHeader('HTTP/1.0', $httpCode, true);
        $this->getResponse()->setBody($response);
    }        
}

abstract class Vendor_React_Controller_AbstractController extends Mage_Core_Controller_Front_Action
0

The answer was simple.. just enable gzip in my local php.ini

zlib.output_compression = On

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.