Search code examples
wordpressgzippagespeed

Wordpress: Enabling GZIP compression


According the GTMetrix Page and Googe Pagespeed I need to enable for many ressources the GZIP compression. But www.checkgzipcompression.com says GZIP is enabled. How can I enable my GZIP Compression?


Solution

  • www.checkgzipcompression.com will count GZIP enable even if GZIP is enabled for a single filetype only while pagespeed tools like Pingdom and GTMetrix want you to integrate GZIP compression for all the file types out possible.

    You can enable GZIP compression both manually by updating your .htaccess or by using a plugin which will do the same for you but with a user friendly UI.

    If you want to enable GZIP compression manually, add the following code to your .htaccess file in your WP root directory.

    <IfModule mod_deflate.c>
        # Compress HTML, CSS, JavaScript, Text, XML and fonts
        AddOutputFilterByType DEFLATE application/javascript
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
        AddOutputFilterByType DEFLATE application/x-font
        AddOutputFilterByType DEFLATE application/x-font-opentype
        AddOutputFilterByType DEFLATE application/x-font-otf
        AddOutputFilterByType DEFLATE application/x-font-truetype
        AddOutputFilterByType DEFLATE application/x-font-ttf
        AddOutputFilterByType DEFLATE application/x-javascript
        AddOutputFilterByType DEFLATE application/xhtml+xml
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE font/opentype
        AddOutputFilterByType DEFLATE font/otf
        AddOutputFilterByType DEFLATE font/ttf
        AddOutputFilterByType DEFLATE image/svg+xml
        AddOutputFilterByType DEFLATE image/x-icon
        AddOutputFilterByType DEFLATE text/css
        AddOutputFilterByType DEFLATE text/html
        AddOutputFilterByType DEFLATE text/javascript
        AddOutputFilterByType DEFLATE text/plain
        AddOutputFilterByType DEFLATE text/xml
    
        # Remove browser bugs (only needed for really old browsers)
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4\.0[678] no-gzip
        BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
        Header append Vary User-Agent
    </IfModule>
    

    The above code is for Apache server. If you're on NGINX server, use this code instead in nginx.conf file:

    gzip on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_vary on;
    gzip_types text/plain text/css text/javascript image/svg+xml image/x-icon application/javascript application/x-javascript;
    

    Now, GZIP compression can be enabled with many caching plugins, popular of them is W3 Total Cache. Check this article on how to setup W3 Total Cache and it's GZIP compression module.

    Code Source