Skip to content

Commit

Permalink
feat: add cache control
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 committed Sep 20, 2024
1 parent 0eb3714 commit d383254
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions 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 @@ -144,8 +144,11 @@ def get(self, *args, **kwargs):
"dnt": dnt and service.respect_dnt,
}
),
content_type="application/javascript",
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)
Expand Down

0 comments on commit d383254

Please sign in to comment.