How can I make sure that static content is cached client-side? How can I make sure that static content is cached client-side? asp.net asp.net

How can I make sure that static content is cached client-side?


Will recommend you to go through this tutorial to understand how caching happens on web (HTTP) in general.

Simply speaking, the web server needs to generate appropriate HTTP headers while sending the content to the client in order to control client-side caching. In ASP.NET/IIS environment, its IIS that typically handles the static file contents and therefore, you must configure IIS appropriately to control caching static files as per you needs. See below links for more information about configuring IIS caching for static content:

http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache
How to configure static content cache per folder and extension in IIS7?

EDIT: As you have asked about the best approach, the most prevalent approach that I see now days is to version static content (say by appending some version identifier at the end of file or URL). Once version-ed, you can treat it as immutable and then emit cache headers for caching it for infinite duration. In ASP.NET application, you can probably append the assembly version (or product version) to each static content URL. So essentially, you will invalidating the cache for every build (or every product release).


You can also make use of the HTML5 Offline web applications manifest. It allows you to set up a manifest where you define which files will be cached locally.

It is a nice, clear to understand broadly implemented, way of avoiding having to learn about IIS and HTML Caching.

http://www.w3schools.com/html/html5_app_cache.asp

(you should totally read up about those things)