1

compress static assets

This commit is contained in:
Motiejus Jakštys 2024-01-13 15:12:05 +02:00
parent 59026d0fb6
commit 81988555d2
2 changed files with 31 additions and 10 deletions

View File

@ -1,17 +1,16 @@
from pathlib import Path
from os import environ
# All that comes from the environment needs to be defined here
_DEBUG = bool(environ.get('E11SYNC_DEBUG', False))
_COMPRESS_OFFLINE = bool(environ.get('E11SYNC_COMPRESS_OFFLINE', False))
_STATIC_ROOT = environ.get('E11SYNC_STATIC_ROOT', '/tmp/e11sync-static')
_GEOIP_PATH = environ.get("GEOIP_PATH")
_GEOIP_PATH = environ.get('GEOIP_PATH')
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
########################################
## No more side effects after this place
########################################
SECRET_KEY = 'django-insecure-$e2!=equ(efm0e%f9&t+xjtz0)$*$@pw%rnjdqcl8f@5o5hw!l'
@ -105,9 +104,27 @@ STATICFILES_FINDERS = [
STATIC_ROOT = _STATIC_ROOT
# At the time of testing:
# main-full.css: 34K
# main-mini.css: 49K
# main-full.css.br: 5.0K
# main-mini.css.br: 7.1K
#
# Minifying those files will necessitate sourcemaps, which
# is not currently possible due to
# https://github.com/django-compressor/django-compressor/issues/438
# Since the savings with minification are not that huge, let's keep
# it a bir larger, but much simpler.
COMPRESS_ENABLED = True
COMPRESS_OFFLINE = _COMPRESS_OFFLINE
COMPRESS_FILTERS = {
'css': [],
'js': [],
}
COMPRESS_PRECOMPILERS = (
# TODO: --style=compressed + source maps
# https://github.com/django-compressor/django-compressor/issues/438
('text/x-scss', 'sass {infile} {outfile}'),
)

View File

@ -63,11 +63,15 @@
];
buildPhase = ''
mkdir -p $out/static
env \
E11SYNC_STATIC_ROOT=$out/static \
E11SYNC_DEBUG= \
${pkgs.python3}/bin/python3 \
${self}/app/manage.py collectstatic
export E11SYNC_STATIC_ROOT=$out/static
export E11SYNC_DEBUG=
export E11SYNC_COMPRESS_OFFLINE=1
${pkgs.python3}/bin/python3 ${self}/app/manage.py collectstatic
${pkgs.python3}/bin/python3 ${self}/app/manage.py compress
${pkgs.findutils}/bin/find $out/static/CACHE -name '*.css' | \
${pkgs.findutils}/bin/xargs -P8 -I{} sh -c \
"${pkgs.zopfli}/bin/zopfli {} && ${pkgs.brotli}/bin/brotli {}"
'';
};
devShells.default = pkgs.mkShellNoCC {