fantactuka
fantactuka

Reputation: 3334

JSF with timestamp

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> 

Upvotes: 0

Views: 1227

Answers (2)

BalusC
BalusC

Reputation: 1108642

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 :)

Upvotes: 4

Bozho
Bozho

Reputation: 597046

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.

Upvotes: 3

Related Questions