开发者

JSF with timestamp

开发者 https://www.devze.com 2023-01-12 14:22 出处:网络
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 ?

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开发者_如何学Python.g:

<script type="text/javascript"  src="file.js?ts=#{timestamp}"></script> 


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号