Include a javascript for composite component only

2019-02-22 02:21发布

How do I include a JavaScript code only once for multiple usages of a composite component on a page?

Initially I had put I put the JS code inside the cc:implementation tags but that lead to the script being included each time with the components. I want to avoid this condition and include the JavaScript only once even if component has been used multiple times on a page.

1条回答
我想做一个坏孩纸
2楼-- · 2019-02-22 02:43

Include the static part of that JS code as a standalone JS file by <h:outputScript> with target="head". It'll be rendered into <h:head> just once.

<cc:implementation>
    <h:outputScript name="js/myCompositeHelper.js" target="head" />
    ...
</cc:implementation>
查看更多
登录 后发表回答