Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Created November 20, 2012 11:36
Show Gist options
  • Select an option

  • Save JamieMason/4117426 to your computer and use it in GitHub Desktop.

Select an option

Save JamieMason/4117426 to your computer and use it in GitHub Desktop.
Asterisk: Compare file size before/after HTML Minification & gzip
#!/bin/bash
# example usage `./asterisk_compare http://www.nytimes.com nytimes`
# "http://www.nytimes.com"
url=$1
# "nytimes"
file_name=$2
# concat file names
original="$file_name.html"
minified="$file_name.min.html"
# name log file
log_file="asterisk-report.txt"
# ensure a log file exists
touch $log_file
# show we're working
echo ""
echo "Processing $url..."
# write out url as a header
echo $url >> $log_file
echo "------------------------------------------------------------" >> $log_file
# minify original with default settings
echo `asterisk --inspect --url $url --output $minified` >> $log_file
# download original file
curl --silent $url > $original
# gzip copy of original and log size
gzip --best --force $original
# gzip copy of minified and log size
gzip --best --force $minified
# log file sizes and compression
echo "" >> $log_file
gzip --list $original >> $log_file
gzip --list $minified >> $log_file
echo "" >> $log_file
echo "" >> $log_file
# clean up
rm $original.gz
rm $minified.gz
@JamieMason
Copy link
Copy Markdown
Author

HTML Minification gzip size comparison tool

Compare file size before and after HTML Minification and gzipping. Minification is done using a CSS-aware HTML Minifier to ensure the layouts of the files are unchanged.

Example Usage

./asterisk_compare http://www.nytimes.com nytimes && \
./asterisk_compare http://www.google.com google && \
./asterisk_compare http://www.facebook.com facebook && \
./asterisk_compare http://www.youtube.com youtube && \
./asterisk_compare http://www.wikipedia.org wikipedia && \
./asterisk_compare http://www.bbc.co.uk bbc && \
open asterisk-report.txt

Output

http://www.nytimes.com
------------------------------------------------------------
1577/1577 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              36132              173328  79.2% nytimes.html
         compressed        uncompressed  ratio uncompressed_name
              33884              159116  78.7% nytimes.min.html


http://www.google.com
------------------------------------------------------------
178/178 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
                203                 221  25.3% google.html
         compressed        uncompressed  ratio uncompressed_name
              15714               50935  69.2% google.min.html


http://www.facebook.com
------------------------------------------------------------
400/400 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
                 34                   0   0.0% facebook.html
         compressed        uncompressed  ratio uncompressed_name
              10210               32894  69.1% facebook.min.html


http://www.youtube.com
------------------------------------------------------------
1886/1886 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              20003              176127  88.7% youtube.html
         compressed        uncompressed  ratio uncompressed_name
              17380              149549  88.4% youtube.min.html


http://www.wikipedia.org
------------------------------------------------------------
645/645 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              11546               46203  75.1% wikipedia.html
         compressed        uncompressed  ratio uncompressed_name
              10496               38994  73.2% wikipedia.min.html


http://www.bbc.co.uk
------------------------------------------------------------
476/476 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              13419               54916  75.6% bbc.html
         compressed        uncompressed  ratio uncompressed_name
              11695               44796  74.0% bbc.min.html


http://www.nytimes.com
------------------------------------------------------------
1562/1562 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              36118              173790  79.2% nytimes.html
         compressed        uncompressed  ratio uncompressed_name
              34032              159858  78.7% nytimes.min.html


http://www.google.com
------------------------------------------------------------
178/178 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
                203                 221  25.3% google.html
         compressed        uncompressed  ratio uncompressed_name
              15711               50915  69.2% google.min.html


http://www.facebook.com
------------------------------------------------------------
400/400 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
                 34                   0   0.0% facebook.html
         compressed        uncompressed  ratio uncompressed_name
              10305               33518  69.4% facebook.min.html


http://www.youtube.com
------------------------------------------------------------
1880/1880 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              19929              176386  88.7% youtube.html
         compressed        uncompressed  ratio uncompressed_name
              17291              149210  88.4% youtube.min.html


http://www.wikipedia.org
------------------------------------------------------------
645/645 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              11546               46203  75.1% wikipedia.html
         compressed        uncompressed  ratio uncompressed_name
              10496               38994  73.2% wikipedia.min.html


http://www.bbc.co.uk
------------------------------------------------------------
476/476 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              13430               54927  75.6% bbc.html
         compressed        uncompressed  ratio uncompressed_name
              11716               44807  73.9% bbc.min.html


http://www.nytimes.com
------------------------------------------------------------
1556/1556 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              36147              173431  79.2% nytimes.html
         compressed        uncompressed  ratio uncompressed_name
              33834              156925  78.5% nytimes.min.html


http://www.google.com
------------------------------------------------------------
178/178 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
                203                 221  25.3% google.html
         compressed        uncompressed  ratio uncompressed_name
              15725               50983  69.2% google.min.html


http://www.facebook.com
------------------------------------------------------------
400/400 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
                 34                   0   0.0% facebook.html
         compressed        uncompressed  ratio uncompressed_name
              10196               32864  69.1% facebook.min.html


http://www.youtube.com
------------------------------------------------------------
1885/1885 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              19936              176179  88.7% youtube.html
         compressed        uncompressed  ratio uncompressed_name
              17394              149774  88.4% youtube.min.html


http://www.wikipedia.org
------------------------------------------------------------
645/645 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              11546               46203  75.1% wikipedia.html
         compressed        uncompressed  ratio uncompressed_name
              10496               38994  73.2% wikipedia.min.html


http://www.bbc.co.uk
------------------------------------------------------------
476/476 elements with layout unaffected after minification

         compressed        uncompressed  ratio uncompressed_name
              13431               54931  75.6% bbc.html
         compressed        uncompressed  ratio uncompressed_name
              11717               44811  73.9% bbc.min.html

@JamieMason
Copy link
Copy Markdown
Author

Apologies for pasting the log output twice - also worth noting that http://google.com and http://facebook.com are already minified, resulting in a degradation of performance by doing it twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment