HTTP headers - cache issue

I request an image, and the response headers I return are as follows:

Accept-Ranges:bytes Content-Length:4499 Content-Type:image/png Date:Tue, 24 May 2011 20:09:39 GMT ETag:"0cfe867f5b8cb1:0" Last-Modified:Thu, 20 Jan 2011 22:57:26 GMT Server:Microsoft-IIS/7.5 X-Powered-By:ASP.NET 

Note the missing Cache-Control header.

On subsequent requests in Chrome, Chrome knows how to go to the cache to get the image. How does he know how to use the cache? I got the impression that I should have said this with the Cache-Control heading.

+1
source share
2 answers

You have an ETag and Last-Modified header. This probably uses. But for this, you still need to make a request with If-None-Match or If-Modified-Since respectively.

+3
source

To install Cache-Control, you must specify it yourself. You can either do this in web.config, IIS Manager for selected folders (static, images ...) or install it in code. The HTTP 1.1 standard recommends in the future as the maximum validity period.

Setting future expiration dates is considered good practice for all static content on your site. Not having If-Modified-Since results in the headers, which may require longer than the first time queries for small static files. These calls use the ETag header.

When you have Cache-Control: max-age=315360000 , the main HTTP responses exceed the number of If-Modified-Since> calls, and because of this, it is good to remove the ETag header and result in smaller response headers for static files. IIS has no settings for this, so you need to do response.Headers.Remove("ETag"); in OnPreServerRequestHeaders()

And if you want to optimize your headers further, you can remove X-Powered-By:ASP.NET in the IIS settings and the X-Aspnet-Version header (although I don't see in your answer) in web.config - enableVersionHeader="false" in system.web / httpRuntime element.

For more advice, I offer an excellent book - http://www.amazon.com/Ultra-Fast-ASP-NET-Build-Ultra-Scalable- Server / dp / 1430223839

+1
source

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


All Articles