Enable GZip Middleware
A snippet showing how to enable GZipMiddleware for performance.
# settings.py
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.middleware.gzip.GZipMiddleware", # enable compression
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
# ...
]
Explanation:
- GZipMiddleware compresses text-based responses (HTML/JSON/CSS/JS) when clients support gzip.
- GZipMiddleware is a simple and effective way to improve performance.
- Category Performance & Optimization
- Total Views 543
- Last Modified 24 April, 2026
- Tags #performance #middleware #gzip #optimization
Previous snippet
Use Cached Sessions
Next snippet