问题描述
我已经使用JSF 2.0创建了一个Web应用程序.我收到朋友的反馈,说我应该进行浏览器缓存",因为我有很多图像.
I have created a web application using JSF 2.0. I got feedback from my friend saying I should do "Browser Caching" as I have many images.
但是我不知道如何在JSF中执行相同的操作.任何想法/提示将不胜感激.
However I don't know how to do same in JSF. Any idea/ hint would be appreciated.
关于要做的事情的概念也将起作用.
Concept on what to be done would also work.
推荐答案
只需使用<h:graphicImage name="...">
而不是<img src="...">
.这样,默认的JSF资源处理程序将默认指示浏览器将其缓存1周,这可以使用依赖于实现的上下文参数进行配置,对于Mojarra,该参数如下:
Just use <h:graphicImage name="...">
instead of <img src="...">
. This way the default JSF resource handler will instruct the browser to cache them for 1 week by default, which is configureable with an implementation dependent context parameter, which is the following in case of Mojarra:
<context-param>
<param-name>com.sun.faces.defaultResourceMaxAge</param-name>
<param-value>3628800000</param-value> <!-- 6 weeks -->
</context-param>
请注意,使用<h:outputScript>
和<h:outputStylesheet>
代替<script>
和<link rel="stylesheet">
时也是如此.
Note, the same applies when using <h:outputScript>
and <h:outputStylesheet>
instead of <script>
and <link rel="stylesheet">
.
这篇关于如何在jsf中启用浏览器缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!