skip to Main Content

I am currently running Magento 2.1.14 and have enable gzip per the Magento documentation as well as the other well visited posts on this site. I have also doubled checked with my hosting provider that Mod_deflate is enabled on the server side.

In addition, I have a copy of my site on my local machine with same htaccess files as what resides on our live server.

On my local machine, simply enabling the apache module and then adding the htaccess code in the main htaccess file of the public_html directory works. All requests on my local site show headers that contain “Content Encoding: gzip”.

However, when live using https on our server, the gzip encoding seems to stop at the pub directory. NO content coming from the pub directory (pub/static and pub/media) shows and gzip encoding. The files on my local machine and live server are the same. According to my hosting provider, gzipped is enabled on their side and they believe that is has to do with one of the htaccess files in my file tree that is stopping the gzip encoding from happening.

I did a small test recommended by our hosting provider as well, and tried to set up an extra directory in the public_html directory on both my local machine and the live server to test if the gzip encoding would work. On my local machine, I can visit the directory and the file in it shows gzip compression, but on my live server, when adding the file to my public_html directory and attempting to visit it through the browser, Magento throws a 404 error!

Does anyone out there have any idea why gzip would not waterfall through my file tree and properly gzip the js, minified js, css and minified css files that are located in the pub folder?

2

Answers


  1. Chosen as BEST ANSWER

    After days of debugging it turns out that on my live server, the RequestHeader for Set-Encoding was being stripped. This was not happening on my Apache setup on my local machine. My web host still has not give me an explanation why this was happening, nor do I know if it has to do with the htaccess file in the pub/static directory, but adding the RequestHeader set below:

    <IfModule mod_headers.c>
    Header set X-UA-Compatible "IE=edge"
    Header set Connection keep-alive
    #THE LINE BELOW THIS COMMENT
    RequestHeader set Accept-Encoding "gzip, deflate, br"  
    <FilesMatch ".(appcache|atom|bbaw|bmp|crx|css|cur|eot|f4[abpv]|flv|geojson|gif|htc|ico|jpe?g|js|json(ld)?|m4[av]|manifest|map|mp4|oex|og[agv]|opus|otf|pdf|png|rdf|rss|safariextz|svgz?|swf|topojson|tt[cf]|txt|vcard|vcf|vtt|webapp|web[mp]|webmanifest|woff2?|xloc|xml|xpi)$">
        Header unset X-UA-Compatible
    </FilesMatch>
    

    to the htaccess file in the root of my magento site fixed the issue with the compression.

    If this is a server issue, I would like someone to comment below on what I might bring up with my webhost to address this. Otherwise, I'm going to submit an issue to the Magento github.


  2. Very strange issue,
    deflate mode included in .htaccess of pub/static

    bat not for all file types,
    javascript files not added to setting

    so,
    just edit pub/static/.htaccess

    and edit row with start – AddOutputFilterByType DEFLATE

    and add content type –

    text/javascript application/javascript application/x-javascript application/json image/svg+xml
    

    now, all static content will with gzip.

    Strange, why was missed this,
    maybe for other features ?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search