I got a recommendation to add Gzip to my site (for better page loading and thus better SEO). How can one apply that to Drupal? Thanks very much indeed !

Comments

nevets’s picture

That is a function of your web server and will depend on where/how the site is hosted.

Jaypan’s picture

Yes, it has nothing to do with Drupal, as it is done at the server level.

VM’s picture

If you've mod_deflate enabled you can test the following to drupal's .htaccess

# enable mod_deflate for compression of text, html, javascript, css, 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

if mod_gzip you can test the following to drupal's .htaccess

<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>
Ayesh’s picture

This will send compressed content regardless of browser headers, I'm guessing ?

// Ayesh
(Latest blog post: Drupal bad practices)

VM’s picture

I can't explain the technical aspects. testing mod_deflate on my own site did increase page loading times.

Ayesh’s picture

This will send compressed content regardless of browser headers, I'm guessing ?

// Ayesh
(Latest blog post: Drupal bad practices)

TMDHosting’s picture

You can use this tool to see if gzip compression is working on your site:

http://www.whatsmyip.org/http-compression-test/

VM’s picture

reading the core .htaccess files I'm not sure why the addition helps. Core's already existing rules are:

# Rules to correctly serve gzip compressed CSS and JS files.
  # Requires both mod_rewrite and mod_headers to be enabled.
  <IfModule mod_headers.c>
    # Serve gzip compressed CSS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.css $1\.css\.gz [QSA]

    # Serve gzip compressed JS files if they exist and the client accepts gzip.
    RewriteCond %{HTTP:Accept-encoding} gzip
    RewriteCond %{REQUEST_FILENAME}\.gz -s
    RewriteRule ^(.*)\.js $1\.js\.gz [QSA]

    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
    RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]

    <FilesMatch "(\.js\.gz|\.css\.gz)$">
      # Serve correct encoding type.
      Header set Content-Encoding gzip
      # Force proxies to cache gzipped & non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
  </IfModule>
</IfModule>