Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要将所有 JS 脚本从“head”标签移动到“body”标签的底部,以提高应用程序的速度。我知道,这需要使用 PhaseListener,但是如何从中获取页面内容呢?
假设您的实际问题是:如何在页面底部而不是在 HEAD 区域呈现 JavaScript 引用?
我建议使用 h:outputScript 标签,它确保脚本只获得一次引用,并且您可以控制渲染位置。
文档: http ://docs.oracle.com/cd/E17802_01/j2ee/javaee/javaserverfaces/2.0/docs/pdldocs/facelets/h/outputScript.html
例子:
<h:outputScript library="js" name="myScript.js" target="body" />
这将在页面正文的底部呈现脚本引用,与您在视图中放置 Facelet 标记的位置无关。