Chrome ignores ETag header and just uses cache cache / cache in cache

If I understand correctly, the thread for using ETag works as described now:

  • The browser sends a request to the server. Server sends back image from ETag
  • Browser saves resource with ETag
  • At the next request, the browser sends a request with a header If-None-Matchcontaining the saved ETag.

When returning the response, chrome dev tools says these are my headers

Cache-Control:max-age=7200
Connection:keep-alive
Content-Type:image/png
Date:Thu, 27 Apr 2017 13:42:57 GMT
ETag:"b36f59c868d4678033d318a182658e18371df8f5"
Expires:Thu, 27 Apr 2017 15:42:57 GMT
Server:nginx
Transfer-Encoding:chunked
X-Debug-Token:873c8f
X-Debug-Token-Link:http://localhost:8081/_profiler/873c8f

Now when I reload the page, the new image is not going to. It is saved via the Chrome cache or disk cache, as you can see here

Chrome dev tab

But why is this happening? I sent ETag, so why the browser does not make another request to the server, but uses its own cache?

, , , , , . Chrome ?


, Firefox , "", .

2
,

Cache-Control:max-age=0, private
Connection:keep-alive
Content-Type:image/png
Date:Thu, 27 Apr 2017 14:44:57 GMT
ETag:"e5b18bdebe44ed4bba3acb6584d9e6a81692ee27"
Expires:Fri, 27 Oct 2017 14:44:57 GMT
Server:nginx
Transfer-Encoding:chunked
X-Debug-Token:3447a6
X-Debug-Token-Link:http://localhost:8081/_profiler/3447a6

Chrome - . nginx

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
  access_log off;
  add_header Cache-Control "max-age: 0, must-revalidate";
}

3
. Expires , Chrome . max-age. , must-revalidate, Expires max-age=>0, Chrome .

+6
2

chrome, 2 (7200 ). , .

max-age: 0 , , max-age: 0, must-revalidate. , ( ), 304 Not Modified, , ( ), , -, 300 , , , .

+3

, .

@Musterknabe 3:

, , must-revalidate chrome . , , - /, -, ( ) . , must-revalidate

, :
1. - ,
2. ( startup.cs) - . .

    public void Configure(IApplicationBuilder app)
    {
        app.UseStaticFiles(new StaticFileOptions
        {
            OnPrepareResponse = ctx =>
            {
                const int durationInSeconds = 0;
                ctx.Context.Response.Headers[HeaderNames.CacheControl] =
                    "must-revalidate,max-age=" + durationInSeconds;
            }
        });
    }

, .

0

Source: https://habr.com/ru/post/1675805/


All Articles