JSF 2浏览器不缓存资源

时间:2014-04-11 16:06:12

标签: jsf caching jsf-2 primefaces

我有一个JSF组件,它通过一个按钮通过ajax请求刷新。该组件具有按值变化的图像。如果我查看网络请求,我可以看到我的浏览器没有缓存图像,但每次点击都会请求它们。这导致了某种类型的弹出"在视图渲染中。

我希望通过缓存图像来加快刷新时间和渲染时间。我尝试在GET方法上使用RequestFilter,它将Cache-Control标头设置为" public"但是没有用。

有什么想法吗?

LatencyIndi​​cator

<!-- IMPLEMENTATION -->
<composite:implementation>
    <h:panelGrid columns="2">
        <c:choose>
            <c:when test="#{cc.attrs.latencia ge cc.attrs.umbralAlto}">
                <p:graphicImage value="#{resource['images:rojo.png']}"/>
            </c:when>
            <c:when test="#{(cc.attrs.latencia lt cc.attrs.umbralAlto) and (cc.attrs.latencia ge cc.attrs.umbralMedio)}">
                <p:graphicImage value="#{resource['images:ambar.png']}"/>
            </c:when>
            <c:otherwise>
                <p:graphicImage value="#{resource['images:verde.png']}"/>
            </c:otherwise>
        </c:choose>
        <h:outputText value="#{cc.attrs.latencia} ms."/>
    </h:panelGrid>
</composite:implementation>

Sample.xhtml

<h:body>
    <h:form id="miForm">
        <h:commandButton id="boton" value="Generar Latencia">
            <f:ajax render="@form" event="click" listener="#{latencyBean.actualizarLatencia()}"/>
        </h:commandButton>
        <miscomponentes:LatencyIndicator latencia="#{latencyBean.latencia}"/>
    </h:form>
</h:body>

1 个答案:

答案 0 :(得分:4)

这可能有多种原因:

  • 您是否通过Development中的上下文参数javax.faces.PROJECT_STAGE将项目阶段设置为web.xml?因为在这种情况下JSF禁用缓存。将参数设置为Production(默认值)应启用缓存。
  • 您使用的是2.1.21以下的Mojarra版本吗?旧版本中存在一个阻止缓存的错误。在这种情况下,您可以尝试新版本。
相关问题