Skip to content

Commit

Permalink
feat: add cache control (#337)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tetuaoro authored Dec 19, 2024
1 parent 0eb3714 commit d07380b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion shynet/analytics/views/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit d07380b

Please sign in to comment.