You are not logged in Log in Join
You are here: Home » Members » dsteven » Enable GZIP compression for a CMF/Plone Site

Log in
Name

Password

 

Enable GZIP compression for a CMF/Plone Site

 

Created by dsteven . Last modified 2004-01-10 03:10:55.

How to enable gzip content-encoding for all or part of your zope site.

I am just getting into plone, but have played with Zope for quite a while. I knew that Zope 2.6+ had inbuild support for gzip content encoding, but wasn't sure how to enable it.

In the past, I always used apache to gzip content to save me some bandwidth, and with plone 2, my front page was on the order of 200k without gzip. However, apache (2.0.40) was not keen to compress the big style sheets or javascript, so I edited HTTPResponse.py, and turned on gzip encoding for allowed types. Page was now around 100k - much better size for a first visitor.

This is the wrong way to do it.

My solution was to use the Set Access Rule feature.

  • Create a python script in the folder you want to enable compression for (I did it in the root of my Plone site). I called it access_rule
  • in the folder, add Set Access Rule, and enter access_rule as the name

Here is my access_rule

request = container.REQUEST
RESPONSE =  request.RESPONSE

if request.REQUEST_METHOD == 'GET': request.RESPONSE.enableHTTPCompression(REQUEST=request)

Be careful - some older browsers can deal with gzip text/html etc, but barf on javascript and css. I've only tested with ie6 and Mozilla.

The method restriction stop WebDAV breaking.

I hope this helps