Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update common_settings.py for precompressing static files #2411 #3898

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions config/settings/common_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,21 @@ def pipe_delim(pipe_string):
# The files need to served in brotli or gzip compressed format
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

# Enable the use of WhiteNoise to serve static files with precompression support (Brotli and Gzip)
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

# WhiteNoise Settings
WHITENOISE_MAX_AGE = 31536000 # One year cache for static files
WHITENOISE_ALLOW_ALL_ORIGINS = True # CORS support for static files

# Brotli compression settings (WhiteNoise automatically supports Brotli)
WHITENOISE_USE_BROTLI = True

# Ensure static files are compressed during `collectstatic`
# This will create `.gz` and `.br` versions of each static file.
COMPRESS_PRECOMPRESS_GZIP = True
COMPRESS_PRECOMPRESS_BROTLI = True

# Media files (uploaded by the user)
DEFAULT_MEDIA_ROOT = os.path.join(BASE_DIR, '.media/')
MEDIA_ROOT = os.environ.get('MEDIA_ROOT', default=DEFAULT_MEDIA_ROOT)
Expand Down