1

When I reload page, Angular directive templates are loaded in two ways. First one - browser makes a request to the server and it responses with 304 - it's ok. When loading from jQuery.ready

But the second one - browser doesn't make a request. And I can't guess why. When loading from within Angular

As a result, when I make changes in templates from the first group, the changes are shown with the next page reload. But the changes in templates from the second group are not shown. That's the trouble.

And the question is - how to make the browser send request to the server for each template?

Mikhail Kopylov
  • 2,008
  • 5
  • 27
  • 58
  • 1
    Please provide response headers for templates in both cases. – miensol May 03 '15 at 18:50
  • @miensol, when first request, cache is clear, response is http://i.imgur.com/3hV9lwu.jpg. When 304, response is http://i.imgur.com/6BusLkx.jpg. When request isn't sent and cache data is used, it looks http://i.imgur.com/fBoE3aD.jpg. – Mikhail Kopylov May 04 '15 at 03:38

1 Answers1

1

It seems that in the response headers for templates there are no Cache-Control headers. In such case a browser will use a heuristic to decide for how long a response can be cached.

To solve your problem of having always fresh templates fetched in development. You can:

  • check "Disable cache" in developer tools
  • set a proper Cache-Control header for resources you care about i.e :

    Cache-Control: no-cache

If you want to understand different behaviours triggered by various Cache-Control values I highly recommend this article by Ilya Grigorik.

Community
  • 1
  • 1
miensol
  • 39,733
  • 7
  • 116
  • 112
  • Thx, @miensol, when setting Cache-Control to max-age=0, browser sends a request on every reload and server returns 304. But when setting to max-age=10 it works wierd: files from the second group are cached for 10 seconds as expected, but the queries from the first group are required from the server with 304 response. Both groups are with Cache-Control & Expires headers. Looks like Chrome uses a heuristic for the first group inspite of Cache-Control headers. Do you know why? – Mikhail Kopylov May 04 '15 at 11:10
  • 1
    Well if I read http specs correctly setting `max-age=10` tells the client (browser in our case) that it's ok to cache the content for at most 10 seconds. In other words it's not saying that the client should not contact the server during that period. – miensol May 04 '15 at 12:13
  • So, it's the browser to decide to follow the max-age=10 attribute or not? Ok, thx! – Mikhail Kopylov May 04 '15 at 16:17
  • 1
    The browser must take max-age=10 into account, but it's up to it decide whether to go to server or not. – miensol May 04 '15 at 16:33