We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18367
    • 834 Posts
    Hi,

    does anybody know the correct way to set gzip compression for Modx Revolution? After searching around the web, no two ways seem to be the same.

    When I check the php info in the Revo Reports it says that Zlib is enabled but compression is turned off.

    There is also an option in System Settings to turn compression on, but it doesn't seem to do anything if you just change the setting.

    I also tried adding the
    php_flag zlib.output_compression on
    into the htaccess folder but that just resulted in a server error for the whole site.

    There was also an option in my cPanel to enable compression for Apache, but that too didn't seem to turn gzip on.

    The next step is to create a php.ini file, but before I do, I just thought I'd ask and see if there's a recommended way to enable compression.

    Thanks
      Content Creator and Copywriter
      • 42046
      • 436 Posts
      It all depends upon your host and what they allow really.

      I use the following htaccess code:

      # compress text, html, php, javascript, css, xml:
      AddOutputFilterByType DEFLATE text/javascript
      AddOutputFilterByType DEFLATE text/plain
      AddOutputFilterByType DEFLATE text/html
      AddOutputFilterByType DEFLATE text/xml
      AddOutputFilterByType DEFLATE text/css
      AddOutputFilterByType DEFLATE application/xml
      AddOutputFilterByType DEFLATE application/xhtml+xml
      AddOutputFilterByType DEFLATE application/rss+xml
      AddOutputFilterByType DEFLATE application/javascript
      AddOutputFilterByType DEFLATE application/x-javascript
      AddOutputFilterByType DEFLATE application/x-httpd-php
      AddOutputFilterByType DEFLATE application/x-httpd-fastphp
      AddOutputFilterByType DEFLATE image/svg+xml
      
      # Drop problematic browsers
      BrowserMatch ^Mozilla/4 gzip-only-text/html
      BrowserMatch ^Mozilla/4\.0[678] no-gzip
      BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
      
      # Make sure proxies don't deliver the wrong content
      Header append Vary User-Agent env=!dont-vary


      Which compresses most things but falls back for old browsers.

      Edit: for this method, it's advisable to have your links tagged with type="text/css" etc

      Another method if mod_zip is installed is:

      # If mod_zip is present the gzip the following content
      <IfModule mod_gzip.c>
        mod_gzip_on                 Yes
        mod_gzip_can_negotiate      Yes
        mod_gzip_dechunk            Yes
        mod_gzip_minimum_file_size  600
        mod_gzip_maximum_file_size  0
        mod_gzip_maximum_inmem_size 100000
        mod_gzip_keep_workfiles     No
        mod_gzip_temp_dir           /usr/local/apache/gzip
        mod_gzip_item_include       file \.html$
        mod_gzip_item_include       file \.txt$
        mod_gzip_item_include       file \.css$
        mod_gzip_item_include       file \.js$
        mod_gzip_item_include       file \.jsp$
        mod_gzip_item_include       file \.php$
        mod_gzip_item_include       file \.pl$
        mod_gzip_item_include       mime ^text/.*
        mod_gzip_item_include       mime ^application/x-httpd-php
        mod_gzip_item_include       mime ^httpd/unix-directory$
        mod_gzip_item_include       handler ^perl-script$
        mod_gzip_item_include       handler ^server-status$
        mod_gzip_item_include       handler ^server-info$
        mod_gzip_item_exclude       mime ^image/.*
      </IfModule>


      If you're using Chrome, the 'Advanced Rest Client' extension is very handy for checking if compression is working in the header responses and measuring page load speed.

      Enabling compression in this way also gives a noticeable speed boost in the manager for me. [ed. note: absent42 last edited this post 11 years, 1 month ago.]
        • 18367
        • 834 Posts
        Thanks Dan,

        I've just found this setting buried away in cPanel

        Optimize the performance of your website by tweaking the way Apache handles requests.
        Compress Content

        Apache 2.0 and 2.2 allow you to compress content before sending it to the visitor's browser. The types of content to be compressed are specified by MIME type. This feature requires Apache's mod_deflate to function correctly.

        Disabled
        Compress all content
        Compress the specified MIME types
        MIME types

        and with a box to enter the MIME types.

        Might investigate that.

          Content Creator and Copywriter
          • 42046
          • 436 Posts
          mod_deflate is the first method which I posted and I use myself.

          You can wrap in a <IfModule mod_deflate.c> ====rules===== </IfModule> to test if your server supports it without breaking the site. Then test with Advanced Rest Client to see if it's working. [ed. note: absent42 last edited this post 11 years, 1 month ago.]
            • 18367
            • 834 Posts
            OK,

            turning that setting on in cPanel did the trick.

            Didn't have to add anything to htaccess but will experiment with your suggestions anyway.
              Content Creator and Copywriter