How to get Mod_pagespeed to output compressed (gzip) css

apache-2.4mod-pagespeedubuntu-14.04

Ubuntu 14.04
Apache 2.4.7
php-FPM 5.5.9

Using latest stable Pagespeed Module for Apache (1.9.32.3-4448).

I'm in the process of optimizing a WordPress website for speed (bandwidth and rendering).
Mod Deflate is set up.
A plugin (Better WordPress Minify) compresses and combines all css files into one (thus reducing the number of requests).
With Pagespeed switched off, if I check the produced link (using FeedTheBot) it confirms that the content is compressed using gzip.
But If Pagespeed is switched on, it shows Gzip is not working. Using PageSpeed Insight (chrome extension) confirms this.

Here is what I've tried:

  • Adding to /etc/apache2/mods-available/pagespeed.conf

    ModPagespeedFetchWithGzip on
    SetOutputFilter DEFLATE
  • check that mod Deflate is available and enabled (it appears in the list produced by apache2ctl -t -D DUMP_MODULES). The fact that if pagespeed is switched off, it works for the combined css file is another proof.

Do you have an explanation ?

Best Answer

This is the way to enable mod_deflate for html,xml,js,css,php files :

# MOD_DEFLATE COMPRESSION
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript application/x-httpd-php
DeflateCompressionLevel 9

# This part is optional, it is used for really old browser >

# DEFLATE NOT COMPATIBLE BROWERS
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# SET VAR
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
Related Topic