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.
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.