ASP.NET Specify which files should be cached
I am developing a website in ASP.NET and I am using various javascript frameworks/libraries. The different files belonging to these frameworks/libraries rarely changes thus there is no reason to refresh those files once they have been sent to the client browser (atleast not everytime a page is served).
I see that the HttpContext object can be used somehow, that I can set the content expiration on the files/folders on the IIS, or maybe setup somekind of caching in the web.config file.
1. What is best practice/what approach should I take?
If the content expiration on the IIS works, then this is just great (and easy). But dur开发者_Go百科ing development, I use the ASP.NET Development Server, which does not interact with the external IIS - thus no performance gain achieved during development :(
2. How can I use cache here (depending on question 1)?
I would like to modify this question to be used as a "this-is-how-its-done" thread for future reference for me and others.
The cache settings in the HttpContext only control how the aspx page is cached, not the caching of files that the browser include (javascript, css, images...).
The browser caches the javascript files by default, and that is pretty much the same regardless if you are running the site locally or live. Normally you have to make a Ctrl+F5 or purge the cache if you make changes in a script to get the browser to load the new version.
So, you don't have to do anything at all, the browswer already caches the files.
I think if you are looking for the caching of the files then that has to be done on the IIS end. You can try YSloy (by Yahoo) extension with FireBug. This is very good and should be used as best practice. Hope that will be helpfull :)
精彩评论