-1

I have a http request /api/speakers/ and I want it to be cached by browser. So I added Cache-Control to the request headers:

headers: {
  'Cache-Control': 'public, must-revalidate, max-age=86400'
}

Request headers

cache-control appears in request headers, but every time it requests it gets new data from response. I am testing without refreshing page, so that is not the problem. What am I doing wrong? How to tell browser to cache request responses and not to request it next one day.

Osman Omar
  • 433
  • 1
  • 7
  • 19
  • Does this answer your question? [Why is Cache-Control attribute sent in request header (client to server)?](https://stackoverflow.com/questions/14541077/why-is-cache-control-attribute-sent-in-request-header-client-to-server) – Joe Apr 17 '21 at 04:20
  • "to the request headers"; the values you use would be typical for *response* headers. – Joe Apr 17 '21 at 04:21
  • @Joe No, my browser is not behaving like it's written here. It sends `cache-control`, but even if it's sent before, it sends request again and again. – Osman Omar Apr 17 '21 at 12:55
  • You say your browser "sends cache-control". These would need to come *from* the server, in the response. – Joe Apr 17 '21 at 14:29
  • @Joe So `cache-control` is not the thing that I write in my code and send it to server? That is the thing that backender should do? – Osman Omar Apr 17 '21 at 14:45

1 Answers1

0

I thought that Cache-control should be sent by frontend, so the browser understands it and caches requests. It turned out that backend sends headers in response so browser can cache requests. In my case, backend written in Django used cache_page and now browser caches everything perfectly.

Osman Omar
  • 433
  • 1
  • 7
  • 19