From 17e2a5f86ab7b4c90f0cb74158bc46bc9e50a6bd Mon Sep 17 00:00:00 2001 From: Marsell Kukuljevic Date: Wed, 28 Apr 2021 17:28:31 +0200 Subject: [PATCH] Add support for serving gzipped static content. Between minification and this, the client-size app is now about 1MB in size when built for production. --- README.md | 9 +++++++-- bin/server.js | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9b9bdb9..31f11ac 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,14 @@ For development: pushd app && ng build && popd -For production (shakes tree and minifies to get smaller size): +For production (shakes tree, minifies and gzips to get smaller size): - pushd app && ng build --prod && popd + pushd app + ng build --prod + for f in $(find dist -type f -not -name '*.html' -not -name '*.png'); do + gzip --best "$f"; + done + popd ## Generate server certificates diff --git a/bin/server.js b/bin/server.js index 510760e..3e82d55 100755 --- a/bin/server.js +++ b/bin/server.js @@ -200,7 +200,8 @@ function main() { // where to serve static content from let staticHandler = mod_restify.plugins.serveStatic({ directory: 'static', - default: 'index.html' + default: 'index.html', + gzip: true }); server.get(STATIC_RE, function staticFunnel(req, res, next) { staticHandler(req, res, function fileFound(err) {