减少 A4J JSF Richfaces 所需的 JavaScript 文件

发布于 2024-12-17 04:21:54 字数 762 浏览 1 评论 0原文

我被要求为使用 JSF/Richfaces/Seam/A4J 的站点提出一些性能改进建议。

我注意到的一件事是,似乎有大量针对 A4J 的 JavaScript 下载。以下是一页的文件列表:

/a4j/g/3_3_3.Finalorg.ajax4jsf.javascript.AjaxScript        
/a4j/g/3_3_3.Finalorg.ajax4jsf.javascript.PrototypeScript   
/a4j/g/3_3_3.Finalorg.ajax4jsf.javascript.ImageCacheScript  
/a4j/g/3_3_3.Finalorg/richfaces/renderkit/html/scripts/browser_info.js
/a4j/g/3_3_3.Finalorg/ajax4jsf/javascript/scripts/form.js   
/a4j/g/3_3_3.Finalscripts/tabPanel.js   
/a4j/g/3_3_3.Finalorg/richfaces/renderkit/html/scripts/skinning.js  
/a4j/g/3_3_3.Finalprototype.js  
/a4j/g/3_3_3.Finalscriptaculous.js

这些文件对于我们正在运行的 JSF 版本来说是静态的,还是根据放入 html 中的 A4J 命令动态创建的?我想知道是否可以安全地将所有这些文件合并到一个文件中,因为它们中的大多数都非常小?如果我这样做,如何阻止这些文件添加到渲染的 HTML 中?

I've been asked to suggest some performance improvements for a site that uses JSF/Richfaces/Seam/A4J.

One thing I've noticed is that there seems to be a lot of JavaScript being downloaded for A4J. Here's a file list from one page:

/a4j/g/3_3_3.Finalorg.ajax4jsf.javascript.AjaxScript        
/a4j/g/3_3_3.Finalorg.ajax4jsf.javascript.PrototypeScript   
/a4j/g/3_3_3.Finalorg.ajax4jsf.javascript.ImageCacheScript  
/a4j/g/3_3_3.Finalorg/richfaces/renderkit/html/scripts/browser_info.js
/a4j/g/3_3_3.Finalorg/ajax4jsf/javascript/scripts/form.js   
/a4j/g/3_3_3.Finalscripts/tabPanel.js   
/a4j/g/3_3_3.Finalorg/richfaces/renderkit/html/scripts/skinning.js  
/a4j/g/3_3_3.Finalprototype.js  
/a4j/g/3_3_3.Finalscriptaculous.js

Are these files static for the JSF version that we are running or are they created dynamically based on the A4J commands that are being put into our html? I'm wondering if it is possible to safely amalgamate all of these into a single file as most of them are very small? If I did that, how would I stop these files from being added to the rendered HTML?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从﹋此江山别 2024-12-24 04:21:54

资源内容不是动态的。 Richfaces 为每个组件依赖项添加特定资源。

我也处于同样的情况,性能是第一位的。我将逐步介绍我为获得一个用于 js 的压缩 richfaces 包和另一个用于 css 的压缩包而采取的操作。

首先,您需要将以下参数添加到 yout web.xml

<context-param>
    <param-name>org.richfaces.LoadStyleStrategy</param-name>
    <param-value>ALL</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.LoadScriptStrategy</param-name>
    <param-value>ALL</param-value>
</context-param>

然后,加载页面并使用 firebug 或任何其他工具提取资源并将它们保存到您自己的服务文件中,例如 richfaces.bundle.js 和 richfaces.bundle。 CSS。

然后,关闭脚本和样式加载:

<context-param>
    <param-name>org.richfaces.LoadStyleStrategy</param-name>
    <param-value>NONE</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.LoadScriptStrategy</param-name>
    <param-value>NONE</param-value>
</context-param>

另一种方法是使用 JAWR 它允许处理单独的资源文件和将它们压缩并捆绑起来。
使用 JAWR,您可以提取 Richfaces 组件特定资源并根据需要加载它们。例如,具有数据表和ajax行为的页面将仅加载JAWR将压缩到单个包中的依赖资源。
这种方法可以提供更好的维护能力。

The resources content is not dynamic. Richfaces add specific resource per component dependencies.

I was in the same situation where performance was at first place. I'll walk thru the actions I've taken in order to get one compressed richfaces bundle for js and another for css.

First of all you need to add the following parameters to yout web.xml

<context-param>
    <param-name>org.richfaces.LoadStyleStrategy</param-name>
    <param-value>ALL</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.LoadScriptStrategy</param-name>
    <param-value>ALL</param-value>
</context-param>

Than, load up a page and using firebug or any other tool extract the resources and save them into your own served file e.g. richfaces.bundle.js and richfaces.bundle.css.

Afterwards, turn off the script and style loading:

<context-param>
    <param-name>org.richfaces.LoadStyleStrategy</param-name>
    <param-value>NONE</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.LoadScriptStrategy</param-name>
    <param-value>NONE</param-value>
</context-param>

Another approach is to use JAWR which allow working on separate resource files and serve them compressed and bundled.
With JAWR you can extract Richfaces component specific resources and load them per your need. e.g. a page with data table and ajax behavior will load only the depended resources which JAWR will compress into a single bundle.
This approach allow better maintenance abilities.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文