From 6ce885541681950735802be3d8080b29d129cb8f Mon Sep 17 00:00:00 2001 From: tetuaoro <65575727+tetuaoro@users.noreply.github.com> Date: Sun, 17 Nov 2024 20:15:53 +0100 Subject: [PATCH] feat: add cache control - due to google analytics and page speed insights check-up, remove the warning by adding a cache policy to the header injected script - set cache control header with max-age of 1 year for script.js --- shynet/analytics/views/ingress.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shynet/analytics/views/ingress.py b/shynet/analytics/views/ingress.py index 49dcfda0..2855f580 100644 --- a/shynet/analytics/views/ingress.py +++ b/shynet/analytics/views/ingress.py @@ -132,7 +132,7 @@ def get(self, *args, **kwargs): dnt = self.request.META.get("HTTP_DNT", "0").strip() == "1" service_uuid = self.kwargs.get("service_uuid") service = Service.objects.get(pk=service_uuid, status=Service.ACTIVE) - return render( + response = render( self.request, "analytics/scripts/page.js", context=dict( @@ -147,6 +147,9 @@ def get(self, *args, **kwargs): content_type="application/javascript", ) + response["Cache-Control"] = "public, max-age=31536000" # 1 year + return response + def post(self, *args, **kwargs): payload = json.loads(self.request.body) ingress(