12

I need to setup Gzip compression for a Magento project. I have tried many code in the .htaccess file in my project, but weren't able to enable Gzip.

Please give me the right solution.

  • Are you talking about gzip compression to improve site performance? – Mukesh Sep 9 '15 at 10:06
  • yes, tell me how to compression? – Kishan Kothari Sep 9 '15 at 10:07
  • Have you solve this problem yet?? – Nitesh Mar 29 '17 at 11:03
9

Make sure mod_deflate is on in Apache. You can check by creating an info.php file and calling phpinfo();. It will output server PHP / Apache specs in the browser. Don't forget to remove it when you're done!

Then add the following to your htaccess file

<IfModule mod_php5.c>
    ## enable resulting html compression
   php_flag zlib.output_compression on
</IfModule>

<IfModule mod_deflate.c>

    ## Force compression for mangled `Accept-Encoding` request headers
    <IfModule mod_setenvif.c>
        <IfModule mod_headers.c>
            SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
            RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
        </IfModule>
    </IfModule>

    ## Compress all output labeled with one of the following media types.
    <IfModule mod_filter.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"

    </IfModule>

    ## Map the following filename extensions to the specified
    ## encoding type in order to make Apache serve the file types
    ## with the appropriate `Content-Encoding` response header
    ## (do note that this will NOT make Apache compress them!).
    <IfModule mod_mime.c>
        AddEncoding gzip              svgz
    </IfModule>

</IfModule>
  • hello sander code do not work. i add this code but can not g.zip enable. – Kishan Kothari Sep 9 '15 at 16:40
  • I'll need a bit more than that to help you. Any errors or hints on whats not working? – Sander Mangel Sep 9 '15 at 21:25
  • website is proper work but when i check from this link checkgzipcompression.com than show G.zip not enable. – Kishan Kothari Sep 10 '15 at 10:24
  • Are you sure mod_deflate is on? – Sander Mangel Sep 10 '15 at 10:25
  • yes, sure node is on – Kishan Kothari Sep 10 '15 at 16:53

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.