Tools.gzip doesn't seem to compress content in cherry

I browse my development site using the Yslow tool in Chrome and Firefox, and one of the suggestions is that I gzip the relevant content. As a starting point, I simply added "tools.gzip.on = True" to my [/] configuration. I know that the configuration file and the block are processed correctly, because I also added options for disabling caching in the response headers, since I often change files when developing a site. In my answers, I see the headers "Expires" and "Pragma: no-cache".

For some reason, even after changing the configuration file (and restarting the process, which is not absolutely necessary), Yslow still reports that I am not using gzip. I also used wget and don't see the Content-Encoding header.

Can anyone suggest how else can I check what is happening? I am wondering if the cherry problem is ignoring the gzip setting, or if Yslow is simply mistaken in its facts. I have never had a problem with Yslow before, so I lean toward the first.

I will add that Yslow only says that my external CSS and JavaScript files (served by the same swirl process) should be compressed, although the headers shown by "wget ​​-S" do not show gzip encoding even on the main page (which is dynamic content).

I tried to add "tools.gzip.on = True" to my [/ css] and [/ js] blocks, and I also tried to set the "tools.encode.on = True" parameter in all the same blocks, assuming the encoding must be enabled for gzip to work.

Thanks in advance.

+3
source share
2 answers

3.2 docstring for cherrypy.lib.gzip:

def gzip(compress_level=5, mime_types=['text/html', 'text/plain'], debug=False):
    """Try to gzip the response body if Content-Type in mime_types.

    cherrypy.response.headers['Content-Type'] must be set to one of the
    values in the mime_types arg before calling this function.

    The provided list of mime-types must be of one of the following form:
        * type/subtype
        * type/*
        * type/*+subtype

    No compression is performed if any of the following hold:
        * The client sends no Accept-Encoding request header
        * No 'gzip' or 'x-gzip' is present in the Accept-Encoding header
        * No 'gzip' or 'x-gzip' with a qvalue > 0 is present
        * The 'identity' value is given with a qvalue > 0.

    """

My money is for the MIME type, as you mention JS and CSS. You can change it like this:

[/static]
tools.gzip.mime_types: ['text/html', 'text/plain', 'text/javascript', 'text/css']

In CherryPy 3.2+, you can shorten it to:

[/static]
tools.gzip.mime_types: ['text/*']
+9
source

To make this work for Javascript, I also had to include 'application / *' as mime_type.

The relevant part of my configuration is as follows:

'tools.gzip.on': True,    
'tools.gzip.mime_types': ['text/*', 'application/*'],
+1
source

All Articles