diff options
| author | Alon Levy <alon@pobox.com> | 2015-02-17 12:52:24 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-02-17 12:52:37 +0200 |
| commit | edf91a5ab2a6afa88999403af5b11b722bb0b378 (patch) | |
| tree | 9b4a24506fc1b5ddf04b172948d165d02bca6f5a | |
| parent | 72c0463055f534c642a57b35ab17ec6c1d6c89a5 (diff) | |
client/server: support optimizing with require.js using node run r.js
built is controlled by property do-client-optimize which defaults to
false.
Even if the optimized main is built (single file main-built.js and
source map file main-built.js.map) they are not used unless
rhizi-config.conf client_optimize is set to True which causes app.js to
use main-built.js and not main.js
The resulting file is 687 KiloBytes large. Pretty scary, but it still
loads faster this way. (from very small tests locally). This is without
compression done by the server.
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | build.ant | 17 | ||||
| -rw-r--r-- | res/etc/rhizi-server.conf.example | 5 | ||||
| -rw-r--r-- | res/templates/index.html | 1 | ||||
| -rw-r--r-- | src/client/app.js | 3 | ||||
| -rw-r--r-- | src/server/rz_api.py | 3 | ||||
| -rw-r--r-- | src/server/rz_server.py | 3 |
7 files changed, 32 insertions, 2 deletions
@@ -9,3 +9,5 @@ res/etc/htpasswd res/etc/htpasswd-init-file rhizi-server.log res/etc/rhizi-server.conf +src/client/main-built.js +src/client/main-built.js.map @@ -3,7 +3,7 @@ Rhizi build targets --> -<project name="rhizi-server" default="pkg-deb"> +<project name="rhizi-server" default="pkg-deb" xmlns:if="ant:if"> <macrodef name="rsync"> <attribute name="src" /> @@ -22,12 +22,23 @@ </sequential> </macrodef> + <macrodef name="client-optimize"> + <attribute name="root" /> + <attribute name="build" /> + <sequential> + <exec dir="@{root}" executable="/usr/bin/r.js" failonerror="true"> + <arg line="-o @{build}" /> + </exec> + </sequential> + </macrodef> + <property name="pkg_name" value="rhizi-server" /> <property name="pkg_version" value="0.1.0" /> <property name="buildDir" value="build/${pkg_name}-${pkg_version}" /> <property name="targetDeploymentDir" value="deploy-local" /> <property name="remoteDeployServer" value="rhizi.net" /> <property name="targetDomain" value="rhizi.net" /> + <property name="do-client-optimize" value="false" /> <tstamp> <format property="versionQualifier" pattern="yyyyMMddHHmm" /> @@ -69,6 +80,8 @@ <copy file="res/etc/rhizi-server.conf.example" tofile="res/etc/rhizi-server.conf" /> + <client-optimize if:true="${do-client-optimize}" root="src/client/" build="build.js" /> + <parallel> <rsync src="${src_client}/" dst="${targetDeploymentDir}/static" /> <rsync src="res/client/" dst="${targetDeploymentDir}/static" /> @@ -93,6 +106,8 @@ <property name="filter_list_str" value="-f '- __pycache__/' -f '- *.pyc'" /> + <client-optimize if:true="${do-client-optimize}" root="src/client/" build="build.js" /> + <!-- -l: traverse bin/ -> ../src-py link --> <rsync src="${targetDeploymentDir}/" extraopts="-lL --delete ${filter_list_str}" diff --git a/res/etc/rhizi-server.conf.example b/res/etc/rhizi-server.conf.example index d1281c58..bb535348 100644 --- a/res/etc/rhizi-server.conf.example +++ b/res/etc/rhizi-server.conf.example @@ -49,6 +49,11 @@ access_control = False user_db_path = ./user_db.db # ----------------------------------------------------------------------------- +# Client settings +# +optimized_main = False + +# ----------------------------------------------------------------------------- # Other # DEBUG = True diff --git a/res/templates/index.html b/res/templates/index.html index 72415881..28cbaf51 100644 --- a/res/templates/index.html +++ b/res/templates/index.html @@ -11,6 +11,7 @@ var rz_config = { // set as a global variable 'backend_enabled': true, 'backend__maintain_ws_connection': true, 'feedback_url': '/feedback', + 'optimized_main': {{ rz_config__optimized_main }}, }; </script> <script data-main='/static/app.js' src="/static/lib/require.js"></script> diff --git a/src/client/app.js b/src/client/app.js index 3c5d4328..a3e294ac 100644 --- a/src/client/app.js +++ b/src/client/app.js @@ -19,6 +19,9 @@ } } + if (rz_config.optimized_main) { + config.paths.main = 'main-built'; + } config.urlArgs = (typeof local_config != 'undefined') && local_config.urlArgs; if (window.is_node) { diff --git a/src/server/rz_api.py b/src/server/rz_api.py index 738174ec..e53f19cd 100644 --- a/src/server/rz_api.py +++ b/src/server/rz_api.py @@ -154,4 +154,5 @@ def index(): return render_template('index.html', rz_username=rz_username, rz_config__hostname=hostname, - rz_config__port=port) + rz_config__port=port, + rz_config__optimized_main='true' if current_app.rz_config.optimized_main else 'false') diff --git a/src/server/rz_server.py b/src/server/rz_server.py index 20f0b30f..6868317f 100644 --- a/src/server/rz_server.py +++ b/src/server/rz_server.py @@ -57,6 +57,9 @@ class Config(object): cfg['static_url_path'] = '/static' cfg['user_db_path'] = os.path.join(cfg['config_dir'], 'user_db.db') + # client configuration + cfg['optimized_main'] = False + # Mail settings cfg['mail_hostname'] = 'localhost' cfg['mail_port'] = 25 |
