尽管复合组件本身多次使用,但在页面中仅包含一次用于复合组件的javascript [英] Include a javascript for composite component only once in a page despite of composite components themselves used multiple times

查看:92
本文介绍了尽管复合组件本身多次使用,但在页面中仅包含一次用于复合组件的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在一次页面上多次使用复合组件的情况下仅包含一次JavaScript代码?

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

最初,我已将JS代码放入cc:implementation标记内,但这导致脚本每次都包含在组件中.我想避免这种情况,即使在页面上多次使用组件,也只包含一次JavaScript.

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.

推荐答案

通过.只需将其渲染到<h:head>中一次.

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>

这篇关于尽管复合组件本身多次使用,但在页面中仅包含一次用于复合组件的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆