Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are my aspx pages not being cached on the client?

I have a dynamically generated CSS file. It's fairly large, and has different content for different browsers. It changes very rarely.

So at the top of the .aspx page I have:

<%@ OutputCache Duration="86400" 
                Location="ServerAndClient" 
                VaryByParam="none" 
                VaryByCustom="browser" %>

I have a similar directive against MVC actions that generate dynamic images:

[OutputCache(Duration = 86400, 
             VaryByParam = "none", 
             Location = OutputCacheLocation.ServerAndClient)] 

This should result in the file being cached on the server and the client (but not intermediate proxies) for a day.

The response headers appear to be correct:

HTTP/1.1 200 OK
Cache-Control: private, max-age=83831
Content-Type: text/css; charset=utf-8
Expires: Wed, 09 Jun 2010 08:52:45 GMT
Last-Modified: Tue, 08 Jun 2010 08:52:45 GMT
Vary: *
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Tue, 08 Jun 2010 09:35:34 GMT
Content-Length: 70073

The server side caching works - further requests do not execute the code again.

However the client side caching is broken in two different ways: firstly the content is requested again on every page, despite the fact that it should be cached.

Why does the browser request the content again?

Secondly when the server is asked for the content again it returns an HTTP 200 along with the entire content. It should return an HTTP 304 Not Modified with no body - telling the browser to re-use what it has already downloaded.

How do I make sure that it returns an HTTP 304 when the content hasn't changed?

like image 249
Keith Avatar asked Jun 08 '10 09:06

Keith


People also ask

Are ASPX pages cached?

The bottom line is that any request you make for an ASPX resource will always result in an immediate new fetch from the server as if the page was never cached.

How can we prevent browser from caching an ASPX page?

Use the SetNoStore() method as follows, in the ASPX page: <%@ Page Language=”C#” %> <% Response. Cache. SetNoStore(); Response.

What is a way to cache an asp net page?

To manually cache application data, you can use the MemoryCache class in ASP.NET. ASP.NET also supports output caching, which stores the generated output of pages, controls, and HTTP responses in memory. You can configure output caching declaratively in an ASP.NET Web page or by using settings in the Web. config file.

How do I enable caching in IIS?

Configure Output Caching Through the IIS ManagerFrom the Start menu, click Administrative Tools, and then click Internet Information Services (IIS) Manager. In the tree view on the left side, find your application. Select the Output Caching menu item. In the right column, click Add in the Action menu.


1 Answers

1) Vary: * will cause certain browsers, such as IE, not to cache. Vary: User-Agent might work better (not sure).

2) WRT 200 vs 304: does the client send an If-* header?

like image 159
Julian Reschke Avatar answered Oct 11 '22 07:10

Julian Reschke