• 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

Marcus

Well-known member
#2
The current implementation makes a 30% larger CSS file
Code:
# 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
 

Marcus

Well-known member
#3
This is a test with only three lines that shows the file size output for every gzip level available:
Code:
# 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:
Code:
sed -i "s|\$content = gzencode(\$content, 1);|\$content = gzencode(\$content, 5);|" /path/library/XenForo/Application.php
 

Marcus

Well-known member
#4
Including the time it takes to compress:

Code:
# 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