Skip to content

Commit

Permalink
Replace Closure compiler with UglifyJS 2.
Browse files Browse the repository at this point in the history
Benchmark on my local machine:

Minifier | Time     | Size
---------|----------|--------
Closure  | 30.6 sec | 1012kb
UglifyJS | 11.3 sec | 1008kb

Time -> Time to run tools/minify-js
Size -> Size of static/min

Result:
271% speed improvement
3.97% reduction in size

Most optimizations are on by default and can be disabled to further
decrease the time spend minifying the code base.

Fixes zulip#693.
  • Loading branch information
tommyip committed Dec 26, 2016
1 parent fe803ff commit f4e66de
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 45 deletions.
10 changes: 4 additions & 6 deletions docs/dev-setup-non-vagrant.md
Expand Up @@ -63,7 +63,7 @@ Start by cloning this repository: `git clone
https://github.com/zulip/zulip.git`

```
sudo apt-get install closure-compiler libfreetype6-dev libffi-dev \
sudo apt-get install libfreetype6-dev libffi-dev \
memcached rabbitmq-server libldap2-dev redis-server \
postgresql-server-dev-all libmemcached-dev python-dev \
hunspell-en-us nodejs nodejs-legacy npm git yui-compressor \
Expand Down Expand Up @@ -119,7 +119,7 @@ https://github.com/zulip/zulip.git`
```
sudo add-apt-repository ppa:tabbott/zulip
sudo apt-get update
sudo apt-get install closure-compiler libfreetype6-dev libffi-dev \
sudo apt-get install libfreetype6-dev libffi-dev \
memcached rabbitmq-server libldap2-dev redis-server \
postgresql-server-dev-all libmemcached-dev python-dev \
hunspell-en-us nodejs nodejs-legacy npm git yui-compressor \
Expand All @@ -140,7 +140,7 @@ https://github.com/zulip/zulip.git`
sudo dnf install libffi-devel memcached rabbitmq-server \
openldap-devel python-devel redis postgresql-server \
postgresql-devel postgresql libmemcached-devel freetype-devel \
nodejs npm yuicompressor closure-compiler gettext
nodejs npm yuicompressor gettext
```

Now continue with the [Common to Fedora/CentOS](#common-to-fedora-centos-instructions) instructions below.
Expand Down Expand Up @@ -177,8 +177,7 @@ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noa
sudo yum install libffi-devel memcached rabbitmq-server openldap-devel \
python-devel redis postgresql-server postgresql-devel postgresql \
libmemcached-devel wget python-pip openssl-devel freetype-devel \
libjpeg-turbo-devel zlib-devel nodejs yuicompressor \
closure-compiler gettext
libjpeg-turbo-devel zlib-devel nodejs yuicompressor gettext
# We need these packages to compile tsearch-extras
sudo yum groupinstall "Development Tools"
Expand Down Expand Up @@ -454,4 +453,3 @@ the results in your browser.
Currently, the Docker workflow is substantially less convenient than
the Vagrant workflow and less documented; please contribute to this
guide and the Docker tooling if you are using Docker to develop Zulip!

3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -28,7 +28,8 @@
"nwmatcher": "1.3.6",
"phantomjs-prebuilt": "2.1.7",
"webpack-dev-server": "1.12.1",
"xmlhttprequest": "1.5.0"
"xmlhttprequest": "1.5.0",
"uglify-js": "2.7.5"
},
"scripts": {
"postinstall": "browserify node_modules/sockjs-client/lib/entry.js --standalone SockJS > node_modules/sockjs-client/sockjs.js",
Expand Down
24 changes: 0 additions & 24 deletions puppet/zulip/manifests/static_asset_compiler.pp

This file was deleted.

17 changes: 4 additions & 13 deletions tools/minify-js
Expand Up @@ -83,14 +83,6 @@ if prev_deploy:
changed_files.add(os.path.join(STATIC_PATH, 'js/bundle.js'))

JS_SPECS = settings.JS_SPECS
CLOSURE_BINARY = '/usr/bin/closure-compiler'
if not os.path.exists(CLOSURE_BINARY):
CLOSURE_BINARY = 'tools/closure-compiler/run'
if not os.path.exists(CLOSURE_BINARY):
print("closure-compiler not installed; the Vagrant tools/provision.py installs it via apt "
"or you can manually unpack http://dl.google.com/closure-compiler/compiler-latest.zip to "
"tools/closure-compiler")
sys.exit(1)

# Where to put minified JS and source maps
MIN_DIR = os.path.join(STATIC_PATH, 'min/')
Expand Down Expand Up @@ -122,11 +114,10 @@ for js_group, filespec in six.iteritems(JS_SPECS):

# No previous deploy, or a source file has changed, or copying was
# supposed to work but failed. Thus, minify the JS anew.
# (N.B. we include STATIC_HEADER_FILE before the JavaScripts.
# This way it doesn't throw off the source map.)
cmd = '%s --language_in ECMASCRIPT5 --create_source_map %s %s %s' % (
CLOSURE_BINARY, map_file,
settings.STATIC_HEADER_FILE, ' '.join(in_files))
cmd = ('node_modules/uglify-js/bin/uglifyjs %s '
'--mangle --compress --comments --source-map %s') % (
' '.join(in_files), map_file)

js = subprocess.check_output(cmd, shell=True)

# Write out the JS
Expand Down
1 change: 0 additions & 1 deletion tools/provision.py
Expand Up @@ -108,7 +108,6 @@
POSTGRES_VERSION = POSTGRES_VERSION_MAP[codename]

UBUNTU_COMMON_APT_DEPENDENCIES = [
"closure-compiler",
"memcached",
"rabbitmq-server",
"redis-server",
Expand Down

0 comments on commit f4e66de

Please sign in to comment.