Skip to content

Commit

Permalink
deps: Add option to skip minifying Javascript files.
Browse files Browse the repository at this point in the history
Plotly.js take around 20 seconds to minify with the Closure
compiler so it is taken out.

Fixes zulip#3076.
  • Loading branch information
tommyip authored and timabbott committed Jan 19, 2017
1 parent 2ed598c commit 23a7685
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
13 changes: 12 additions & 1 deletion tools/minify-js
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ for js_group, filespec in six.iteritems(JS_SPECS):
in_files = [os.path.join(STATIC_PATH, filename)
for filename in filespec['source_filenames']]

min_files = [os.path.join(STATIC_PATH, filename)
for filename in filespec.get('minifed_source_filenames')
or []]

out_file = os.path.join(MIN_DIR, os.path.basename(filespec['output_filename']))
map_file = os.path.join(MAP_DIR, os.path.basename(filespec['output_filename'])
+ '.map')

if (not 'force_minify' in filespec) and (prev_deploy and len(set(in_files) & changed_files) == 0):
if (not 'force_minify' in filespec) and \
(prev_deploy and len(set(in_files) & changed_files) == 0):
# Try to reuse the output file from previous deploy
try:
for dest in [out_file, map_file]:
Expand All @@ -132,4 +137,10 @@ for js_group, filespec in six.iteritems(JS_SPECS):

# Write out the JS
with open(out_file, 'wb') as fp:
# Minified source files (most likely libraries) should be loaded
# first to prevent any dependency errors.
for file in min_files:
with open(file, 'rb') as f:
fp.write(f.read())

fp.write(js)
8 changes: 7 additions & 1 deletion zerver/templatetags/minified_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ def __init__(self, sourcefile):
def render(self, context):
# type: (Dict[str, Any]) -> str
if settings.DEBUG:
scripts = settings.JS_SPECS[self.sourcefile]['source_filenames']
source_files = settings.JS_SPECS[self.sourcefile]
normal_source = source_files['source_filenames']
minified_source = source_files.get('minifed_source_filenames')

# Minified source files (most likely libraries) should be loaded
# first to prevent any dependency errors.
scripts = minified_source + normal_source if minified_source else normal_source
else:
scripts = [settings.JS_SPECS[self.sourcefile]['output_filename']]
script_urls = [staticfiles_storage.url(script) for script in scripts]
Expand Down
4 changes: 3 additions & 1 deletion zproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,12 @@ def get_secret(key):
},
'stats': {
'source_filenames': (
'node_modules/plotly.js/dist/plotly.js',
'node_modules/jquery/dist/jquery.js',
'js/portico/stats.js'
),
'minifed_source_filenames': (
'node_modules/plotly.js/dist/plotly.min.js',
),
'output_filename': 'min/stats.js'
},
# We also want to minify sockjs separately for the sockjs iframe transport
Expand Down

0 comments on commit 23a7685

Please sign in to comment.