2

I need some help with WordPress speed optimization via .htaccess.

For now, the website is still running on localhost, XAMPP, Apache v3.2.4.

What I did / tried:

  • turn on GZip in .htaccess
  • enable mod deflate in .htacess
  • place .htaccess in WordPress root directory

Google Lighthouse Speed Test via the Chrome dev tools does not detect:

  • Compression (message: Enable text compression)

When I examine the response header via dev tools, there's no cache-control: ... entry.

I would appreciate some help on how to fix these problems. I figure that I went wrong somewhere in my setup, but I'm not sure where.

So, here's what I did for COMPRESSION in .htacces:

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

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE image/x-icon
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/x-font
    AddOutputFilterByType DEFLATE application/x-font-truetype
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/x-font-otf
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/opentype
    # For Olders Browsers Which Can't Handle Compression
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

<IfModule mod_headers.c>

     RewriteCond %{HTTP:Accept-Encoding} gzip
     RewriteCond %{REQUEST_FILENAME}\.gz -f
     RewriteRule \.(css|ics|js|json|html|svg)$ %{REQUEST_URI}.gz [L]

     # Prevent mod_deflate double gzip
     RewriteRule \.gz$ - [E=no-gzip:1]

     <FilesMatch "\.gz$">

         # Serve correct content types
         <IfModule mod_mime.c>
             # (1)
             RemoveType gz

             # Serve correct content types
             AddType text/css              css.gz
             AddType text/calendar         ics.gz
             AddType text/javascript       js.gz
             AddType application/json      json.gz
             AddType text/html             html.gz
             AddType image/svg+xml         svg.gz

             # Serve correct content charset
             AddCharset utf-8 .css.gz \
                              .ics.gz \
                              .js.gz \
                              .json.gz
         </IfModule>

      # Force proxies to cache gzipped and non-gzipped files separately
      Header append Vary Accept-Encoding

     </FilesMatch>

     # Serve correct encoding type
     AddEncoding gzip .gz

 </IfModule>
Cinder
  • 319
  • 2
  • 15

0 Answers0