我们可以通过输出缓存缓存图像,CSS和Java脚本MVC3? [英] Can we cache images, css and java script in MVC3 through Output Cache?
问题描述
我们能缓存图像,CSS和MVC3任何特定的视图(而不是局部视图)的JavaScript通过的OutputCache属性。像我想缓存我的家庭控制器view.I试过,但只有内容没有缓存的图像和CSS。
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.
推荐答案
而不是输出缓存的属性可以用下面的方法有静态资源的缓存:
Instead of Output Cache attribute you can use following methods to have caching of static resources:
1.使用最大年龄。把下面的web.config部分,在<结构>
- > < system.webServer>
部分
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,使用URL版本。可以通过捆绑来实现。如果你正在使用MVC3你可以看看 combres上的NuGet 。在MVC4以上是内置的选项:捆绑和缩小
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
这篇关于我们可以通过输出缓存缓存图像,CSS和Java脚本MVC3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!