Skip to content

Commit a75153b

Browse files
committed
Force cache on static files to be broken by using hash on names when debug is false
1 parent b357a00 commit a75153b

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ services:
1616
- .envs/.example
1717
environment:
1818
- USE_GRANIAN=True
19+
- USE_POSTGRES=True
1920
healthcheck:
2021
test: ["CMD-SHELL", "curl -f http://localhost:8000/api/v1/status || exit 1"]
2122
interval: 1m30s

run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ USE_GRANIAN=${USE_GRANIAN:-true}
55
USE_GRANIAN=$(echo "$USE_GRANIAN" | tr '[:upper:]' '[:lower:]')
66

77
uv pip list
8-
python src/manage.py collectstatic --no-input
8+
python src/manage.py collectstatic --no-input --clear
99
python src/manage.py migrate
1010
sphinx-build docs/ build/
1111
python src/manage.py compilemessages --ignore .venv --ignore cache

src/config/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def debug(_):
334334
"BACKEND": "config.storage_backends.PublicMediaStorage",
335335
},
336336
"staticfiles": {
337-
"BACKEND": "config.storage_backends.StaticStorage",
337+
"BACKEND": "config.storage_backends.ManifestStaticStorage",
338338
},
339339
}
340340

src/config/storage_backends.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
from django.conf import settings
22
from storages.backends.s3boto3 import S3Boto3Storage
3+
from storages.backends.s3boto3 import S3ManifestStaticStorage as BaseManifestStaticStorage
4+
from storages.backends.s3boto3 import S3StaticStorage
35

46

5-
class StaticStorage(S3Boto3Storage):
7+
class StaticStorage(S3StaticStorage):
68
location = settings.AWS_STATIC_LOCATION
79

810

11+
class ManifestStaticStorage(BaseManifestStaticStorage):
12+
location = settings.AWS_STATIC_LOCATION
13+
14+
def get_object_parameters(self, name):
15+
params = super().get_object_parameters(name)
16+
params["CacheControl"] = "max-age=31536000"
17+
return params
18+
19+
920
class PublicMediaStorage(S3Boto3Storage):
1021
location = settings.AWS_PUBLIC_MEDIA_LOCATION
1122
file_overwrite = False

0 commit comments

Comments
 (0)