1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

30% File Size Improvement: Add gzip compression level in XenForo\Application::gzipContentIfSupported

Discussion in 'XenForo Suggestions' started by Marcus, Mar 1, 2015.

  1. Marcus

    Marcus Well-Known Member

    for CSS Output. function gzipContentIfSupported(&$content, $level) would be perfect, so that the rarely created and cached CSS files are even smaller.

    stringgzencode string $data [, int $level = -[, int $encoding_mode FORCE_GZIP ]] )
    Axel B, GliX, Mouth and 3 others like this.
  2. Marcus

    Marcus Well-Known Member

    The current implementation makes a 30% larger CSS file
    # curl -o css.php https://xenforo.com/community/css.php?css=xenforo,form,public&style=7&dir=LTR&d=1424957087
    # cp css.php css.php-9
    # gzip css.php -1
    # gzip css.php-9 -9
    # ls -lah | awk '{print $5, $9}'
    16K css.php-9.gz
    21K css.php.gz
  3. Marcus

    Marcus Well-Known Member

    This is a test with only three lines that shows the file size output for every gzip level available:
    # curl -o css.php https://xenforo.com/community/css.php?css=xenforo,form,public&style=7&dir=LTR&d=1424957087
    # for i in {1..9}; do cp css.php css.php-$i && gzip css.php-$i -$i; done
    # ls -lah | awk '{print $5, $9}'
    84K css.php
    21K css.php-1.gz
    19K css.php-2.gz
    19K css.php-3.gz
    17K css.php-4.gz
    16K css.php-5.gz
    16K css.php-6.gz
    16K css.php-7.gz
    16K css.php-8.gz
    16K css.php-9.gz
    Quick and dirty file edit to increase compression level to 5 when php takes over compression:
    sed -i "s|\$content = gzencode(\$content, 1);|\$content = gzencode(\$content, 5);|" /path/library/XenForo/Application.php
  4. Marcus

    Marcus Well-Known Member

    Including the time it takes to compress:

    # for i in {1..9}; do cp css.php css.php-$i && START=$(date +%s.%N) && gzip css.php-$i -$i && END=$(date +%s.%N) && DIFF=$(echo "$END - $START" | bc)  && mv css.php-$i.gz css.php-gzip_level:$i-seconds:$DIFF.gz ; done
    # ls -lah | awk '{print $5, $9}'
    84K css.php
    21K css.php-gzip_level:1-seconds:.002500234.gz
    19K css.php-gzip_level:2-seconds:.002505812.gz
    19K css.php-gzip_level:3-seconds:.002744298.gz
    17K css.php-gzip_level:4-seconds:.002758539.gz
    16K css.php-gzip_level:5-seconds:.003160474.gz
    16K css.php-gzip_level:6-seconds:.003726089.gz
    16K css.php-gzip_level:7-seconds:.004091227.gz
    16K css.php-gzip_level:8-seconds:.004373446.gz
    16K css.php-gzip_level:9-seconds:.004191505.gz

Share This Page