Is Chrome ignoring Cache-Control: max-age?

前端 未结 8 1728
南旧
南旧 2020-11-27 02:56

Background:

  • IIS 7
  • AspNet 3.5 web app

Chrome dev tools lists 98 requests for the home page of the web app (aspx + js + css + images). I

相关标签:
8条回答
  • 2020-11-27 03:27

    Quite an old question, but I noticed just recently (2020), that Chrome sometimes ignores the Cache-Control headers for my image resources when browsing using an Incognito window.

    "Sometimes" because in my case the Cache-Control directive was honored for small images (~60-200KB), but not for larger ones (10MB).

    Not using Incognito window resulted in Chrome using the disk cached version even for the large images.

    0 讨论(0)
  • 2020-11-27 03:27

    Another tip:

    Do not forget to verify "Date" header - if server has incorrect date/time (or is located in another time zone) - Chrome will keep requesting resource again and again.

    0 讨论(0)
  • 2020-11-27 03:30

    Chrome appears to be ignoring your Cache-Control settings if you're reloading in the same tab. If you copy the URL to a new tab and load it there, Chrome will respect the cache control tags and reuse the contents from the cache.

    As an example I had this Ruby Sinatra app:

    #!/usr/bin/env ruby
    
    require 'sinatra'
    
    before do
      content_type :txt
    end
    
    get '/' do
      headers "Cache-Control" => "public, must-revalidate, max-age=3600",
              "Expires" => Time.at(Time.now.to_i + (60 * 60)).to_s
      "This page rendered at #{Time.now}."
    end
    

    When I continuously reloaded it in the same Chrome tab it would display the new time.

    This page rendered at 2014-10-08 13:36:46 -0400.
    This page rendered at 2014-10-08 13:36:48 -0400.
    

    The headers looked like this:

    < HTTP/1.1 200 OK
    < Content-Type: text/plain;charset=utf-8
    < Cache-Control: public, must-revalidate, max-age=3600
    < Expires: 2014-10-08 13:36:46 -0400
    < Content-Length: 48
    < X-Content-Type-Options: nosniff
    < Connection: keep-alive
    * Server thin is not blacklisted
    < Server: thin
    

    However accessing the same URL, http://localhost:4567/ from multiple new tabs would recycle the previous result from the cache.

    0 讨论(0)
  • 2020-11-27 03:31

    This is addition to kievic answer

    To force browser to NOT send Cache-Control header in request, open chrome console and type:

    location = "https://your.page.com"
    

    To force browser to add this header click "reload" button.

    0 讨论(0)
  • 2020-11-27 03:32

    After doing some tests with Cache-Control:max-age=xxx:

    • Pressing reload button: header ignored
    • Entering same url any tab (current or not): honored
    • Using JS (window.location.reload()): ignored
    • Using Developer Tools (with Disable cache unselected) or incognito doesn't affect

    So, the best option while developing is put the cursor in the omnibox and press enter instead of refresh button.

    Note: a right button click on refresh icon will show refresh options (Normal, Hard, Empty Cache). Incredibly, no one of these affect on these headers.

    0 讨论(0)
  • 2020-11-27 03:33

    While this question is old, I wanted to add that if you are developing using a self-signed certificate over https and there is an issue with the certificate then google will not cache the response no matter what cache headers you use.

    This is noted in this bug report: https://bugs.chromium.org/p/chromium/issues/detail?id=110649

    0 讨论(0)
提交回复
热议问题