Can we cache images, css and java script in MVC3 through Output Cache?

≯℡__Kan透↙ 提交于 2019-12-24 03:56:07

问题


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



来源:https://stackoverflow.com/questions/18207245/can-we-cache-images-css-and-java-script-in-mvc3-through-output-cache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!