What advantages do JSF's h:outputScript/ h:out

2019-02-14 04:56发布

问题:

Is it preferable to use JSF's h:outputScript or h:outputStylesheet when script/style elements may just work for you ? What advantages does former offer over the latter ?

回答1:

The JSF builtin resource handling has at least the following advantages:

  • Resource versioning
  • Configurable cache control
  • Packaging in JAR
  • Programmatic (component based) manipulation
  • Automatic prepending of right context path
  • EL support in CSS files
  • i18n support (different resource files based on user's locale)
  • Automatic HTTP/2 push (JSF 2.3+ on HTTPS only)

See also:

  • How to reference CSS / JS / image resource in Facelets template?
  • What is the JSF resource library for and how should it be used?


回答2:

Normal script/styles work if you know exactly under which context url the application is deployed.

So if you want to deploy the application under another context url you have to change your jsf code if you use script/style instead of h:outputScript and h:outputStylesheet.