Guru: Speed Up Web Pages Using Apache’s mod_deflate
July 9, 2018 Alan Seiden
If your web applications run on HTTP Server (Powered by Apache) for i, you can enable a powerful Apache extension, mod_deflate, to speed up your site. Just as zipping up files on your PC saves space and accelerates file transfers, mod_deflate “allows output from your server to be compressed before being sent to the client over the network.” (See https://httpd.apache.org/docs/2.4/mod/mod_deflate.html for more information.) My tests show a speed improvement of 10 to 50 percent.
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.
- 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 GURU, then the file is likely to be located at /www/guru/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/.
- Add the following two directives to httpd.conf’s main section (pound signs are comments):
- Use the Start TPC/IP Server CL command to restart your Apache instance (in this case, “GURU”).
STRTCPSVR SERVER(*HTTP) RESTART(*HTTP) HTTPSVR(GURU)
If your site is public, you can type its URL into the box at https://checkgzipcompression.com/ 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.
An IBM Champion and founder of Seiden Group, Alan Seiden leads a team that mentors clients in building APIs and web/mobile applications using open source, PHP, and IBM i business logic. Alan’s passion for the IBM i community inspires him to host the bi-annual CIO Summit and offer a free monthly tips newsletter.