Using content compression with ColdFusion and SSI
This is actually an old story, just wanted to blog this so it might eventually help somebody else...
You probably know that most web-pages you'll find nowadays don't come as plain textfiles through this series of tubes, but the content is actually gzip-compressed server-side and unpacked by your browser, as long as the latter signals the server that it actually digests compressed content, which it usually does by sending the appropriate header.
Anyway, compressing static content is quite simple, you'd use something like mod_deflate with Apache2 or mod_gzip with Apache 1 and I am sure there are similar options for other webservers.
Compression of ColdFusion-generated pages is a little trickier though - mod_deflate doesn't seem to help you here.
Quite while back I stumbled over a blog post from Simon Whatley, "Poor man's HTTP Compression with ColdFusion", which is still a worthwhile read, though I haven't tested it with ColdFusion 8. This was running quite satisfactorily on our servers until I needed to host a CF-application which made heavy use of Server Side Includes for caching purposes. You can probably imagine what happened: Apache requested a CFM page for include as SSI and got some gzipped content back; result: binary gibberish on the including page where the dynamic content should have been.
So I had to deactivate this servlet filter solution and thus compression for all the websites I was hosting, just because one of them was using this exotic SSI-setup. I was not happy with this state of affairs, so I dug a little deeper. The reason why mod_deflate does not kick in is that ColdFusion in fact fails to set the content type correctly which would signal Apache, that this request may be compressed. The culprit was the jrun-connector which used a quite direct method for setting the content type instead of using the Apache API.
I found instructions on which line actually needed to be changed here, though the compile instructions didn't work for me. So here'swhat I did to patch the jrun-connector:
First you need to unpack the connector source:
cd ~/files cp -p /opt/coldfusion8/runtime/lib/wsconfig.jar . unzip wsconfig.jar cd wsconfig/connectors/src/
Now you need to patch mod_jrun22.c like this:
756c756,757 < r->content_type = pstrdup_lower(r, value); --- > // r->content_type = pstrdup_lower(r, value); > ap_set_content_type(r, pstrdup_lower(r, value));
I used the following script to compile the patched connector:
#!/bin/bash export CFMX=/opt/coldfusion8 export APACHE_PATH=/usr/ export APACHE_BIN=$APACHE_PATH/sbin #CFMX connector path eg $CFMX/runtime/lib/wsconfig/1 export CFMX_CONNECTOR=$CFMX/runtime/lib/wsconfig/1 #stop apache /etc/init.d/apache2 stop ${APACHE_BIN}/apxs -c -Wc,-w -n jrun22 -S LIBEXECDIR=${CFMX_CONNECTOR} \ mod_jrun22.c jrun_maptable_impl.c jrun_mutex.c jrun_property.c \ jrun_proxy.c jrun_session.c jrun_utils.c platform.c ${APACHE_BIN}/apxs -i -n jrun22 -S LIBEXECDIR=${CFMX_CONNECTOR} mod_jrun22.la strip $CFMX_CONNECTOR/mod_jrun22.so chmod 775 $CFMX_CONNECTOR/mod_jrun22.so /etc/init.d/apache2 start
Save this as ~/files/wsconfig/connectors/src/build_new_connector.sh and then do the following:
cd /opt/coldfusion8/runtime/lib/wsconfig/1 cp -p mod_jrun22.so mod_jrun22.so.`date -I`.bak cd ~/files/wsconfig/connectors/src/ ./build_new_connector.sh
If compilation fails with /build_new_connector.sh: line 12: /usr/sbin/apxs: File not found, you might need to install some additional packages and maybe set a symlink. I'm on Debian, so I did
aptitude install apache2-prefork-dev apache2-utils apache-dev ln -s /usr/bin/apxs2 /usr/sbin/apxs
Apache will be stopped, the connector will be compiled and installed and Apache will be started up again. The original connector will be backed up. If mod_deflate is installed, active and configured correctly, content compression for your CFM-pages should already work.
You can check the result of your changes using the GZIP-Tester of Whatsmyip.org. You can expect savings of 80% or more per HTML page!

June 29th, 2010 - 11:03
With ColdFusion 9.0.1 this is fixed.I see that the data get compressed without having to modify mod_jrun22.c. Do you want to try?
June 29th, 2010 - 11:08
Thank you for the info. We’re still on ColdFusion 8, so I cannot try if it has been fixed right now, but as the patch is fairly simple I’d have been very much surprised if Adobe hadn’t done anything about it eventually. So that’s another reason for an upgrade