Skip to content

Instantly share code, notes, and snippets.

@infusion
Last active February 3, 2016 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infusion/bbcd543bec900543a799 to your computer and use it in GitHub Desktop.
Save infusion/bbcd543bec900543a799 to your computer and use it in GitHub Desktop.
Closure compiler API call
#!/bin/bash
# A simple helper file for Google Closure compiler
#
# Copyright (c) 2011, Robert Eisele (robert@xarg.org)
# Dual licensed under the MIT or GPL Version 2 licenses.
# Usage: ./generate.sh input.js output.js
curl --silent -d"compilation_level=ADVANCED_OPTIMIZATIONS&output_format=text&output_info=compiled_code" --data-urlencode "js_code@$1" \
http://closure-compiler.appspot.com/compile -o x
gzip -9 -c x > "$2.gz"
mv x "$2"
echo "Done!"
#!/bin/bash
# A simple helper file for Google Closure compiler offline version
#
# Copyright (c) 2015, Robert Eisele (robert@xarg.org)
# Dual licensed under the MIT or GPL Version 2 licenses.
# Usage: ./cc.sh input.js
# Will generate input.min.js
if [[ "$1" == "" ]]; then
echo "$0 <file> [<output>]"
exit
fi
if [[ "$2" == "" ]]; then
out=${1%.*}.min.js
else
out=$2
fi
echo "$1 > $out"
java -jar /Applications/closure-compiler/build/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --js "$1" --js_output_file "$out"
ORIG_SIZE=$(stat -f %z "$1")
COMP_SIZE=$(stat -f %z "$out")
ORIG_GZIP=$(gzip -c -9 "$1" | wc -c | tr -d '[:space:]')
COMP_GZIP=$(gzip -c -9 "$out" | wc -c | tr -d '[:space:]')
echo " Compress: $ORIG_SIZE > $COMP_SIZE"
echo " GZIP: $ORIG_GZIP > $COMP_GZIP"
echo Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment