skip to Main Content

EDITED – I ran speed tests on my site with google page speed insights and some anomalies emerged regarding text compression. I verified that on the site was not active the text compression (Content-Encoding not present in the Response Headers) and then I modified the root htaccess file like this:

# ORIGINAL CODE

<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    <IfModule mod_setenvif.c>
        # Netscape 4.x has some problems...
        BrowserMatch ^Mozilla/4 gzip-only-text/html

        # Netscape 4.06-4.08 have some more problems
        BrowserMatch ^Mozilla/4.0[678] no-gzip

        # MSIE masquerades as Netscape, but it is fine
        # BrowserMatch bMSIE !no-gzip !gzip-only-text/html

        # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
        # the above regex won't work. You can use the following
        # workaround to get the desired effect:
        BrowserMatch bMSI[E] !no-gzip !gzip-only-text/html

        # Don't compress images
        SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    </IfModule>

    <IfModule mod_headers.c>
        # Make sure proxies don't deliver the wrong content
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
</IfModule>

# CODE ADDED TO ACTIVATE COMPRESSION

<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>

I think the server is Apache, in google developer tools it just says:

server: - WordPress Hosting by https://www.vhosting-it.com

However after these changes the speed checker keeps giving me the same errors and I still don’t see the Content-Encoding in the Response Headers. How can I fix it?

2

Answers


  1. Add below code in the .htaccess file.

    <ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </ifModule>

    Hope this will help.

    Login or Signup to reply.
  2. You have added not added the code completely to make it work.

    Do add the below code at end of your .htaccess file

    # BEGIN GZIP COMPRESSION
    <IfModulemod_gzip.c>
    mod_gzip_onYes
    mod_gzip_dechunkYes
    mod_gzip_item_includefile.(html?|txt|css|js|php|pl)$
    mod_gzip_item_includehandler^cgi-script$
    mod_gzip_item_includemime^text/.*
    mod_gzip_item_includemime^application/x-javascript.*
    mod_gzip_item_excludemime^image/.*
    mod_gzip_item_excluderspheader^Content-Encoding:.*gzip.*
    </IfModule>
    # END GZIP COMPRESSION
    

    Add the following line of codes if your website is hosted on a Nginx server.

    gzipon;
    gzip_comp_level2;
    gzip_http_version1.0;
    gzip_proxied any;
    gzip_min_length1100;
    gzip_buffers168k;
    gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_disable"MSIE [1-6].(?!.*SV1)";
    gzip_varyon;
    

    After adding the code you can go to webpagetest or anyother speed test site for confirmation. This will work 100% but, still in any case you will not able to achieve it, can comment below, would love to assist you.

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