0

I have a jsf page that contains some javascript includes. And I want to prevent caching with adding timestamps to its urls. It it possible to do with "plain" jsf without adding java code ?

E.g:

<script type="text/javascript"  src="file.js?ts=#{timestamp}"></script> 
fantactuka
  • 3,298
  • 19
  • 29

2 Answers2

4

An alternative is to declare java.util.Date as managed bean.

<managed-bean>
    <managed-bean-name>date</managed-bean-name>
    <managed-bean-class>java.util.Date</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

This way you can use

#{date.time}

to get the timestamp.


Note that I fully agree with Bozho that this not the proper way to prevent caching. The above is just for your information only. Somepeople needs to learn something new every day :)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
3

This is not quite the proper way to prevent caching. Use a Filter that verifies the requested URI and if there is a .js extension, or a response content-type text/javascript, then add headers that prevent caching. See this answer for a sample implementation.

Community
  • 1
  • 1
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 1
    Interesting. First time I see fmt:timestamp. Where is it documented? At least not [here](https://javaserverfaces.dev.java.net/nonav/docs/2.0/pdldocs/facelets/index.html). – BalusC Aug 18 '10 at 11:33
  • @BalusC hmm, it appears to be caucho-specific jstl. thanks for the note. – Bozho Aug 18 '10 at 11:48