tags:

views:

37

answers:

2

Hi,

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> 
+3  A: 

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.

Bozho
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
@BalusC hmm, it appears to be caucho-specific jstl. thanks for the note.
Bozho
+2  A: 

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