Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Browser Caching in ASP.NET application

Any suggestions on how to do browser caching within a asp.net application. I've found some different methods online but wasn't sure what would be the best. Specifically, I would like to cache my CSS and JS files. They do change, however, it is usually once a month at the most.

like image 587
Jason Avatar asked Jun 05 '09 13:06

Jason


People also ask

What is cache in ASP.NET with example?

For example a contact us page in a main page will be the same for all the users and for that there is no need to cache the entire page. So for that we prefer to use fragment caching option. For example: <%@ OutputCache Duration = 10 VaryByParam = "None" %>

How does browser caching work?

Caching is a process in which data is kept in a cache. A cache is simply a storage area that stores data for a short time. Browser caching is a process that involves the temporary storage of resources in web browsers. A visitor's web browser downloads various website resources and stores them in the local drive.

What is caching in ASP.NET web API?

Caching is the technique of storing the data which are frequently used. Those data can be served faster for any future or subsequent requests by eliminating the unnecessary requests to external data sources.

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. Write (DateTime.


1 Answers

Another technique is to stores you static images, css and js on another server (such as a CDN) which has the Expires header set properly. The advantage of this is two-fold:

  1. The expires header will encourage browsers and proxies to cache these static files
  2. The CDN will offload from your server serving up static files.
  3. By using another domain name for your static content, browsers will download faster. This is because serving resources from four or five different hostnames increases parallelization of downloads.
  4. If the CDN is configured properly and uses cookieless domain then you don't have unnecessary cookies going back and forth.
like image 80
TAG Avatar answered Sep 21 '22 19:09

TAG