Can we cache images, css and javascript of any specific view (not partial view) in MVC3 through OutputCache attribute. like I want to cache my Home Controller view.I tried this but only contents are cached not images and css.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Instead of Output Cache attribute you can use following methods to have caching of static resources:
1.Using max-age. Put below section in web.config in <configuration>
-> <system.webServer>
section
<staticContent>
<!-- Tell client to cache static files for a year -->
<clientCache cacheControlMode="UseMaxAge"
cacheControlMaxAge="365.00:00:00" />
</staticContent>
2.Using URL versioning. Can be done by bundling. If you are using MVC3 you could look at combres on nuget. In MVC4 or above it is build-in option: Bundling and Minification