Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How can I make sure that static content (images, css, javascript) is cached? What is the best approach?

like image 483
Arian Avatar asked Mar 14 '12 06:03

Arian


1 Answers

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).

like image 147
VinayC Avatar answered Sep 20 '22 09:09

VinayC