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.