How to keep last-modifed while keeping Chrome and other browsers from the "from cache"?

Source: Internet
Author: User

I have a Web application, server-side data is generated dynamically, through the program on the server side cache, with last-modified to indicate the update time. But without random numbers on the URL, Google Chrome always "from cache" without initiating a request to the server. Only when the browser turns on "isable cache (while DevTools is open)" Will it be normal for each request to be initiated, the server returns 304 before it is taken from the cache.

I tried to add Cache-control:no-cache, Pragma:no-cache, he always in the second time "from Cache", I need to use last-modifed to reduce the amount of data that the server responds to, Is there any way to solve the problem?

Supplementary questions:

If this address is requested separately, it is normal for the second and third browsers to issue if-modififed-since, but when the request is made within the page, for example, he is always on the first after the from cache, unless added Expires to expire it.

Found someone to mention BUG https://code.google.com/p/chromium/issues/detail?can=2&start=0&num=100&q=&colspec=ID% 20pri%20m%20iteration%20releaseblock%20cr%20status%20owner%20summary%20os%20modified&groupby=&sort= &id=48445, also found that I was the problem last year (last year on the message)

Replacing last-modified with an etag is no longer a problem, and Google is doing just that.

Reply content:

I have a Web application, server-side data is generated dynamically, through the program on the server side cache, with last-modified to indicate the update time. But without random numbers on the URL, Google Chrome always "from cache" without initiating a request to the server. Only when the browser turns on "isable cache (while DevTools is open)" Will it be normal for each request to be initiated, the server returns 304 before it is taken from the cache.

I tried to add Cache-control:no-cache, Pragma:no-cache, he always in the second time "from Cache", I need to use last-modifed to reduce the amount of data that the server responds to, Is there any way to solve the problem?

Supplementary questions:

If this address is requested separately, it is normal for the second and third browsers to issue if-modififed-since, but when the request is made within the page, for example, he is always on the first after the from cache, unless added Expires to expire it.

Found someone to mention BUG https://code.google.com/p/chromium/issues/detail?can=2&start=0&num=100&q=&colspec=ID% 20pri%20m%20iteration%20releaseblock%20cr%20status%20owner%20summary%20os%20modified&groupby=&sort= &id=48445, also found that I was the problem last year (last year on the message)

Replacing last-modified with an etag is no longer a problem, and Google is doing just that.

Good question, I didn't know there was such a hole before. But this is not a browser bug.
Here's a similar question, why are this response being cached?
I translate the answers of Stephen Ostermiller, the answer a little

If you add the last-modified header but do not add the Expires or Cache-control header, the browser has to decide for how long it should cache the resource. Some browsers cache it for more than a day.
Google Caching Best Practices guide says the browser calculates the cache duration based on the last-modified itself.
The method of calculation for Firefox is: 缓存时长 = ( Date - Last-Modified )/ 10 .
Chrome/safari/ie did not publish their formulas or algorithms.
The cache duration of such a file usually depends on the following factors

  • The size of the cache space opened by the browser
  • Number and size of sites viewed by users
  • Whether the user closed the browser

Therefore, if you do not want to delete last-modified and do not want the browser to cache your resources, you should specify the expiration time or cache duration.

The END

Cache-Control: no-cache, no-store, max-age=0Pragma: no-cacheExpires: Sat, 26 Jul 1997 05:00:00 GMT

The above is forbidden for all caches.

But according to your description, I would recommend it.

Cache-Control: max-age=0, private, must-revalidate

Click here:

Then tick the relevant settings

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.