2

I am developing an application using JSF2.0/Primefaces 4.0 and JBoss 7.

The problem is that every time i make a new deployment (using .war), all of the users have to clean their browser cache to see the changes(mainly with images positioning).

I know that browsers save the content of the page to make it run faster, but i also know that there is a way to control the HTTP param cache-control to make it re-validate the page.

And the question is: How to make the client browser recognize that there is a new deployment and clean the stored cache? Of course, using JBoss 7.

Also, i don't want to re-validate the cache in every access, only when there is a new deployment.

Is that possible?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Pellizon
  • 1,365
  • 2
  • 12
  • 26
  • 1
    You have to identify exactly what resource(s) being cached are causing the problems. Is it perhaps modifications to a CSS file? – Gimby Apr 22 '14 at 14:45

2 Answers2

3

I would suggest to use the build in JSF resource library mechanism, which supports versioning of resources. Since the clients caches will load a given resource when its' path changes. This way you can change the version number of your resoures and urge the client to reload them, without having to deal with any cache ageing strategies.

There are several good write-ups about this topic here on SO

Community
  • 1
  • 1
cheffe
  • 9,345
  • 2
  • 46
  • 57
2

If it's the css file that is being cached, you can use this code to add a version to your css file. This way you don't have to maintain the version yourself.

<h:outputStylesheet>
@import url('/someFolder/resources/css/page.css?v=${applicationInfoBean.projectVersion}')
</h:outputStylesheet>  

Where applicationInfoBean.projectVersion is my own bean and a method which return the current project version.

Another way is to change the time of how long the ResourceHandlers are caching the resources. The default time is one week. You can change that in Mojarra:

<context-param>
    <param-name>com.sun.faces.defaultResourceMaxAge</param-name>
    <param-value>28800000</param-value> <!-- 8 hours. --> 
</context-param>

And in MyFaces:

<context-param>
    <param-name>org.apache.myfaces.RESOURCE_MAX_TIME_EXPIRES</param-name>
    <param-value>3628800000</param-value> <!-- 6 weeks. -->
</context-param>
Emil Kaminski
  • 1,886
  • 2
  • 16
  • 26
  • Nice answer! This way should work fine, but i think that versioning by JSF resource library is a better practice. Thank you anyway :) – Pellizon Apr 23 '14 at 09:59