Speed Up Web Pages Using Apache’s mod_deflate

Apache HTTP Server ProjectWhen we do performance assessments for web applications running on HTTP Server (Powered by Apache) for i, one of the first things we do is enable a powerful Apache extension called mod_deflate. Just as zipping up files on your PC saves space and accelerates file transfers, mod_deflate compresses output from your server before sending it over your network.

Does it really work? My tests show a speed improvement of 10 to 50 percent!

In fact, one of the reasons CommunityPlus+ PHP runs so fast out of the box is that we automatically turn on mod_deflate during CP+ installation.

If you’re not using CP+ PHP and want to speed up your site, check out mod_deflate. You can compress any text-based output, including HTML (whether plain .html files, output from RPG CGI programs, PHP, or other languages), Cascading Style Sheets (CSS), and Javascript (JS) — pretty much anything except compressed images and other binary formats.

Content is compressed automatically, sent over the network to the browser as usual, and then automatically decompressed by the user’s browser. By default, the gzip compression protocol is used because most browsers support it.

Follow these easy steps to enable mod_deflate.

  1. Edit the appropriate Apache instance configuration file. Its location will depend on your web server instance name. For example, if your Apache instance is named MYSITE, then the file is likely to be located at /www/mysite/conf/httpd.conf. This is a simple text file, so you may choose from several editors: IBM’s HTTP Server Admin GUI at port 2001 (if *ADMIN is started), the WRKLNK/EDTF command, or your favorite text editor.
  2. Add the following two directives to httpd.conf’s main section (pound signs are comments):
# Load the extension that deflates (compresses) content
LoadModule deflate_module /QSYS.LIB/QHTTPSVR.LIB/QZSRCORE.SRVPGM
# Specify what content to compress (example: html, json, css, javascript)
# Make sure this directive has no line breaks; it should fit on one line in your .conf file.
 AddOutputFilterByType DEFLATE application/x-httpd-php application/json text/css application/x-javascript application/javascript text/html
  1. Use the Start TPC/IP Server CL command to restart your Apache instance (in this case, “MYSITE”).
STRTCPSVR SERVER(*HTTP) RESTART(*HTTP) HTTPSVR(MYSITE)

If your site is public, you can type its URL into the box at https://www.giftofspeed.com/gzip-test/ to learn whether compression has been enabled, and how much bandwidth you saved. When I tested my site, seidengroup.com, I learned that compression was, indeed, enabled, reducing page size from 73,911 bytes to 15,171 bytes, quite a savings.

If your site is not public, you can use your browser’s “developer tools” to check for compression. Instructions for Google Chrome’s browser are at https://www.conetix.com.au/support/article/how-to-check-gzip-is-enabled.

Smart developers may ask whether the dynamic compression/decompression causes any performance penalty. In my experience, any minor slowdown from on-the-fly compression/decompression is far outweighed by the benefits of smaller file sizes. Compression algorithms have been optimized over the years to be very fast.  I say, therefore, compress first and ask questions later!

Try mod_deflate on your IBM i-based sites (and other sites) and let us know your results.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.