1

Ok, this is a really simple one. I have been trying to compress the home page of my site to pass the Google PageSpeed test. All of my assets such as CSS and Javascript files are compressed but the page itself is not. The report states: -

Google PageSpeed Issue

My Htaccess file is as follows: -

<IfModule mod_deflate.c>
    AddType image/svg+xml .svg
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-httpd-php
</IfModule>

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access 1 month"
    ExpiresByType image/jpeg "access 1 month"
    ExpiresByType image/gif "access 1 month"
    ExpiresByType image/png "access 1 month"
    ExpiresByType text/css "access 1 month"
    ExpiresByType text/html "access 1 month"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresByType image/x-icon "access 1 month"
    ExpiresByType image/svg+xml "access 1 month"
    ExpiresDefault "access 1 month"
</IfModule>

Any help would be greatly appreciated.

Matt Toner
  • 226
  • 2
  • 11

1 Answers1

1

I assume that is because your GZIP code is not covering every resource that your website is using, try and replace it with the following code, it has a much more extensive cover:

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

NOTE: I also noticed you have a number of external JavaScript files being run, if you want to be able to cache these, see my answer here: Leverage Browser Caching for 3rd party JS

Joe
  • 4,877
  • 5
  • 30
  • 51
  • Hi @thickguru. Unfortunately, I have run the test again with your code and it still has the same result :/. Is this because the page is dynamically loaded? – Matt Toner Aug 04 '17 at 08:38
  • No, that shouldn't affect it :/..... Looking at your headers too you're set too `Accept-Encoding: "gzip, deflate, br"`. The only thing it is potentially missing there is `compress`. – Joe Aug 04 '17 at 09:00
  • Hi @thickguru, we have just changed our server to Litespeed and your code has started to work. Happy to give you this one mate. Thank you. – Matt Toner Aug 04 '17 at 11:08