0

I've read through a number of caching methods, but am still quite unsure of how to approach this.

I have a web application which uses .aspx, .html, .css, .js I want to cache my pages, but not my ajax requests. I also have themes, so images are requested like so:

<img src="/Content/Images/Theme/<%=WebApp.Global.GetSetting("CurrentTheme",Request)%>/Image.png"/>

Where WebApp.Global.GetSetting gets the current theme name to direct the image path.

My .css and theme images are selected based on theme name and so they may be changed regularly. The .js, .html, and .aspx always remain the same, barring the ajax requests in the .js.

I would appreciate some guidelines and resources which would point me in the right direction.

Thank You!

Bob
  • 3,074
  • 11
  • 43
  • 62

1 Answers1

2

For asp.net apps there are many different kinds of caching available. This includes browser caching, partial page caching, data caching, and others.

The first and foremost is browser caching. Browsers will automatically cache references to your js, css, and images. Although you might need to add the following to your web.config to give it a hint about the js files:

<staticContent>
    <remove fileExtension=".js" />
    <mimeMap mimeType="text/javascript" fileExtension=".js"/>
</staticContent>

The can also have the following to give it a hint on how long to cache the static content:

<staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
</staticContent>

For the actual pages, see one of the links above. You have pretty good control over what is and isn't cached in the app itself.

Community
  • 1
  • 1
NotMe
  • 87,343
  • 27
  • 171
  • 245