dotCMS tuning: compress content with the GZip Tomcat filter
So dotCMS is going slowly, how do you speed it up? A cheap and easy solution is to compress content before it gets sent to the browser, where the browser will then decompress that content on the fly.
I just roughed this in on a 2.5.4 install, but for some time, Tomcat has shipped with a GZip filter by default. GZip is the module/filter/mechanism that can provide content zipped on the server to reduce the overall network traffic required to serve up content. Unless your server resources are severely limited, I’ve never seen a case where this wasn’t awesome. Rarely is it not a good idea to enable GZip on the server.
And did I mention it’s a relatively simple maneuver?
Skip this bit if you know about the infamous "configuration plugin"
-
Unlike dotCMS 1.x, with dotCMS 2.x, you configure dotCMS w/ the static "configuration plugin."
-
This is not an OSGI plugin. So for this new configuration to “take”, you’re going to need to refresh your plugins between a dotCMS shutdown and startup in this order:
-
shut down
-
undeploy-plugins
-
deploy-plugins
-
start up
-
The configuration plugin lives in
$dotcms_home/plugins/com.dotcms.config/
-
This is configuration that overrides anything from
$dotcms_home/tomcat/config/server.xml
Configuration Location
-
This config will take place in
$dotcms_home/plugins/com.dotcms.config/ROOT/tomcat/conf/server.xml.
- Be sure to maintain your existing connector attributes, and merely append your connector attributes with the GZip goods.
The Goods
In your server.xml
file, you’ll enable GZip and tell GZip which file types are to be compressed for both of your HTTP and HTTPS connectors.
HTTP
<ConnectormaxThreads="130"connectionTimeout="3000"port="80"protocol="HTTP/1.1"redirectPort="8443"compression="on"compressionMinSize="2048"noCompressionUserAgents="gozilla, traviata"URIEncoding="UTF-8"compressableMimeType="text/plain,text/html,text/xml,text/css,application/xml,application/xhtml+xml,application/rss+xml,application/javascript,application/x-javascript,text/javascript,text/json,application/json" />
HTTPS
<Connectorport="443"protocol="HTTP/1.1"SSLEnabled="true"maxThreads="300"scheme="https"secure="true"clientAuth="false"sslProtocol="TLS"keystoreFile="../temp.jks"keyAlias="tomcat"keystorePass="dotcms"compression="on"compressionMinSize="2048"noCompressionUserAgents="gozilla, traviata"URIEncoding="UTF-8"compressableMimeType="text/plain,text/html,text/xml,text/css,application/xml,application/xhtml+xml,application/rss+xml,application/javascript,application/x-javascript,text/javascript,text/json,application/json" />
Now demonstrate
You’ve laid in this new configuration, how do you ensure that what you just did yielded expected effects? I’m a Chrome Browser user, so I use the Chrome Developer console.
-
Browse to the page you want to see GZipped
-
Open up your Developer Console (in OSX: [OPTION] + [CMD] + J)
-
Head over to the Network tab
-
Left-click on the top request in your network tab and you’ll see one of the following
This means something isn’t quite right, content is coming over uncompressed
If you did it right, you'll see something like this:
We hope this helps. We ask that all questions, comments, criticisms are moved in to comments below (instead of email, Facebook, Twitter, etc) to help future readers. We’re happy to engage you in blog comments and answer any questions you may have or if you're in need of one-on-one consulting, please feel free to contact us.