tags:

views:

38

answers:

1

Hi guys, I have page which consists of couple fragments and in the "header" fragment I have this tag <webuijsf:script id="script_logo" url="/resources/logo.js"/>. This is rendered in HTML as <script src="/app/resources/logo.js" type="text/javascript" id="Header:script_logo"></script>. This is fine and it is working as expected. Now I need to force JSF somehow to return URL to the javascript with current version of app. This is known technique for forcing the reload of resource (javascript, css and images) in case they are cashed on client's side. I need to render something like <script src="/app/resources/logo.js?ver=1.0.405" type="text/javascript" id="Header:script_logo"></script>. Please note the ver parameter in the URL.
Thanks.
Tomas

+2  A: 

Well, you can simply add it to the page:

<script src="/app/resources/logo.js?ver=#{commonBean.version}" ...>

I've assumed you want to version to be configurable and sent by the server, so commonBean is some jsf bean that returns the proper version.

Update: also take a look at <rich:loadScritp>. (from RichFaces)

The final option is to create your own component and include the version automatically. Look for tutorial for how to make that, it's not easy for JSF 1.2

Bozho
I was thinking about something more generic where I don't have to go through the code and add to every occurence of the `<script>` tag some new stuff. Something like servlet which will be mapped to the '/resource/' path and do the trick to add some artificial parameter. Or a new renderer for the `<script>` tag which will do the same as the servlet.
Tomas Babic
@Tomas Babic it wouldn't be much of a difference. Anyway, see my update.
Bozho
@Bozho it does make difference. I don't want to go through every page and fragment and update all ocurences of my images, css and scripts tags with this `?ver=#{someBean.version}` code. There has to be more generic aproach.
Tomas Babic
@Tomas Babic - you can make your own component. But it's not easy.
Bozho
You would be ready in less time than the time you needed for this question :)
BalusC