pip install django-compressor
python
INSTALLED_APPS = [
...
'compressor',
...
]
python
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
COMPRESS_ENABLED = True
python
MIDDLEWARE = [
...
'compressor.middleware.CompressorMiddleware',
...
]
django
{% load compress %}
{% compress css %}
<link rel="stylesheet" href="{% static 'css/style1.css' %}">
<link rel="stylesheet" href="{% static 'css/style2.css' %}">
{% endcompress %}
{% compress js %}
<script src="{% static 'js/script1.js' %}"></script>
<script src="{% static 'js/script2.js' %}"></script>
{% endcompress %}
python manage.py collectstatic