T
T
twintwin10032015-03-09 16:03:50
Nginx
twintwin1003, 2015-03-09 16:03:50

Client side nginx caching?

Understanding nginx server setup. I got to the caching point, and I can’t understand some points:
1) I don’t specify in the config that nginx would give the header with caching on the client side. I go to localhost -> I check through the developer tools (Google chrome) -> the server answered 200 OK I
update -> the server answered 304 Not Modified
Question: why 304? I did not specify caching in the config.
2) Here the question is more about understanding what caching is. In my understanding: the
server gave a js script for example -> the browser put it in the cache -> the browser waits until the cache is up to date Cache-Control:max-age=60
BUT, I decided to immediately change the js script, and updated the page. In theory, the browser should have checked the cache validity time, if not OK, then re-request, but no, it took and downloaded the modified js script, with a logical server response of 200 OK.
I will listen to any options and suggestions from:

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2015-03-10
@twintwin1003

First, all caching headers are just a "strong recommendation". The browser can always request any resource for any reason.
Secondly, refreshing a page with F5/Ctrl-R is not the same as simply navigating from another page or from the address bar. When you click "reload" the browser thinks you really need the latest version and adds some headers to the request and also forces a re-request of the cached data.
But at the same time, thirdly, the request indicates the state of the data in the browser cache (Last Modified, Etag, maybe something else) and if the server believes that the browser has up-to-date data, it can respond with 304, so as not to reload in vain data again.

A
Armenian Radio, 2015-03-09
@gbg

The browser is not a fool, it caches on its own initiative. The first time he downloaded, the second time he asked - "has it changed?", The server answered "no", the browser was glad and did not download.
If you change the content, the browser will receive 200 again in response to the request and will be forced to download.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question