Batakj
Batakj

Reputation: 12743

How to force browser to reload h:outputScript resource?

The JS file extra.js is included as follows:

<h:outputScript library="js" name="extra.js"  />

I am facing issue of browser caching. Many times, I will not get the updated copy.

In plain HTML, we used to append version number or random number with JS URL like:

<script type="text/javascript" src="http://yyy.zzzz.net/js/tryjs?v=1234"></script>
where v is the version number.

Is there any way to add some version number to the generated resource URL in h:outputScript?

Upvotes: 3

Views: 2921

Answers (1)

Daniel
Daniel

Reputation: 37061

You can do one of the following

Manage the version number in one of you beans #{myBean.myVersion} and append it to you js file in h:outputScript

Like this:

<h:outputScript library="js" name="extra.js?#{myBean.myVersion}/>

or rename your js file to include the #{myBean.myVersion} as a part of its name like this

<h:outputScript library="js" name="extra.#{myBean.myVersion}.js/>

Also you can take a look at this : Resources (Library) In JSF 2.0

Upvotes: 5

Related Questions