From 291f859a4f2bae986c2ade65fc2ec3f6a261f73f Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Wed, 4 Apr 2018 16:02:05 +0200 Subject: [PATCH] Use Flask-Assets to minify self-hosted JS files (#468) * Use Flask-Assets to minify self-hosted JS files By having Flask-Assets minify the two JS files we ship, namely main.js and bootstrap-select.js, we can shave off 28406 bytes. The minified files are generated on startup. If one wishes to manually clean them up or build them, they can use the "flask assets" management command, e.g. "flask assets clean". * Workaround to fix tests State carries over in tests, which is the dumbest shit ever. Fix it by clearing the bundles before setting them. --- nyaa/__init__.py | 6 ++++++ nyaa/templates/layout.html | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/nyaa/__init__.py b/nyaa/__init__.py index f2d33fc..e743c6f 100644 --- a/nyaa/__init__.py +++ b/nyaa/__init__.py @@ -81,6 +81,12 @@ def create_app(config): # Assets assets.init_app(app) + assets._named_bundles = {} # Hack to fix state carrying over in tests + main_js = Bundle('js/main.js', filters='rjsmin', output='js/main.min.js') + bs_js = Bundle('js/bootstrap-select.js', filters='rjsmin', + output='js/bootstrap-select.min.js') + assets.register('main_js', main_js) + assets.register('bs_js', bs_js) # css = Bundle('style.scss', filters='libsass', # output='style.css', depends='**/*.scss') # assets.register('style_all', css) diff --git a/nyaa/templates/layout.html b/nyaa/templates/layout.html index 5ad403e..325f796 100644 --- a/nyaa/templates/layout.html +++ b/nyaa/templates/layout.html @@ -45,8 +45,12 @@ - - + {% assets "bs_js" %} + + {% endassets %} + {% assets "main_js" %} + + {% endassets %}