Browsers seem to ignore the response cache management instruction

I'm trying to check the cache configuration, I want my page to remain in the cache for 1 minute before the request reaches the server again.

Using this simple test.asp page that has a link to itself:

<% Option Explicit %> <% Response.Expires = 1 Response.CacheControl = "private, max-age=60" %> <html> <head><title>test</title></head> <body> <% =Now() %> <br /> <a href="test.asp">test</a> </body> </html> 

This works fine on my development computer http: //localhost/test.asp (clicking the link does not update the print date within 1 minute).

However, it does not have the desired effect when I put the page on a production server. After a few seconds of clicking the link, I get a new datetime, meaning that the request has reached the web server.

I use the Chrome dev tool and see these response headers:

 HTTP/1.1 200 OK Cache-Control: private, max-age=60 Content-Type: text/html Expires: Tue, 12 May 2015 19:16:52 GMT Last-Modified: Tue, 12 May 2015 19:10:00 GMT Server: Microsoft-IIS/7.5 X-Powered-By: ASP.NET Date: Tue, 12 May 2015 19:15:55 GMT Content-Length: 205 

Can someone explain why it does not work on the prod server?

update I tried with Chrome, Firefox and IE, as well as 2 pages test.asp and test2.asp that have a link to another page, and got exactly the same problem, after 8-12 seconds the page was updated instead of waiting 60 seconds before refreshing .

+7
browser-cache asp-classic
source share
1 answer

To follow my comment, it looks like you can look for caching your dynamic asp pages on the server, not the client. Client caching is really not very useful, because modern browsers / proxies will still request an element when its an HTML document. Caching static resources that do not change, such as images, css, js, should work, and depending on the cache header that you pop, the browser will respect them.

So that your pages are cached on the server (this means that IIS does not need to recreate the page), here's how you do it.

Web.config

 <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <caching> <profiles> <add extension=".asp" policy="CacheForTimePeriod" kernelCachePolicy="DontCache" duration="00:01:00" /> </profiles> </caching> </system.webServer> </configuration> 

You can put your web.config in a specific directory only to cache its contents, you can also split the caching using querystring parameters or specific request headers.

0
source share

All Articles