简体   繁体   English

JSF Richfaces前端性能调优

[英]JSF Richfaces frontend performance tuning

I've developed a web application using MyFaces 1.2.6 and Richfaces 3.3.1GA (just upgrated). 我使用MyFaces 1.2.6和Richfaces 3.3.1GA(刚刚升级)开发了一个Web应用程序。 Despite the ease of use, I found out that Richfaces components are very slow. 尽管易于使用,但我发现Richfaces组件非常慢。

I also found out that they didn't really take advantage of the browser caching mechanism, they keep sending some lousy JS file every request and other things. 我还发现他们并没有真正利用浏览器缓存机制,他们不断发送一些糟糕的JS文件,每个请求和其他东西。 I really would like to apply some rules described in the "High PErformance WEbsites" book, but I can't change de generated js and HTML code. 我真的想应用“High PErformance WEbsites”一书中描述的一些规则,但我无法更改de生成的js和HTML代码。

Does anyone have some tips for frontend performance tuning using Richfaces? 有没有人有使用Richfaces进行前端性能调整的一些技巧?

Thanks. 谢谢。

Have a read of this article . 阅读本文

Are you using Firebug + YSlow to check what is being stored in the cache? 您是否使用Firebug + YSlow来检查缓存中存储的内容? Using the web.xml org.richfaces.LoadScriptStrategy setting, you can tell Richfaces to either: 使用web.xml org.richfaces.LoadScriptStrategy设置,您可以告诉Richfaces:

  • Load all script in one file. 将所有脚本加载到一个文件中。
  • Load no scripts (you do it yourself instead - eg. in the manner prescribed by your book). 不加载任何脚本(您可以自己完成 - 例如,按照您的书规定的方式)。
  • Load scripts when needed (the default). 需要时加载脚本(默认)。

But some basic principles : 但一些基本原则:

  • Never put logic into your getters. 永远不要把逻辑放入你的吸气剂。 They are called multiple times and should only return something already populated by another method. 它们被多次调用,并且只应返回已由另一个方法填充的内容。 For example if you are chaining drop-downs together use an a4j:support tag on the first one with an action attribute that loads the data which is then retrieved when you reRender the second one. 例如,如果要链接下拉列表,请在第一个上使用a4j:support标记,并使用action属性加载数据,然后在reRender第二个时检索该数据。

  • Use the ajaxSingle="true" unless you actually want to send the whole form back to the server. 使用ajaxSingle="true"除非您确实要将整个表单发送回服务器。

  • Don't use a rich component if you only need a normal one. 如果您只需要一个普通的组件,请不要使用丰富的组件。 For example don't use rich:dataTable unless you are making use of some of the features that it has over and above h:dataTable . 例如,不要使用rich:dataTable除非您正在使用它在h:dataTable之上和之上的一些功能。

You can use: org.ajax4jsf.DEFAULT_EXPIRE 31536000 您可以使用:org.ajax4jsf.DEFAULT_EXPIRE 31536000

So that all js, css files (generated by richfaces) are cached for 1 year on the browser. 这样所有js,css文件(由richfaces生成)都会在浏览器上缓存1年。 This really improved speed in our project. 这确实提高了我们项目的速度。

Also, we do not need to worry about if we change richfaces version as when we change richfaces version it will generate different files. 此外,我们不需要担心如果我们更改richfaces版本,因为当我们更改richfaces版本时它将生成不同的文件。

To add on to Damo, you can also add a small filter to cache such js or images to improve the performance. 要添加到Damo,您还可以添加一个小过滤器来缓存此类j或图像以提高性能。 But exert caution in doing this, if files intended to cach involve frequent updates. 但是,如果要进行缓存的文件涉及频繁更新,请谨慎行事。

private void cacheImages(HttpServletRequest request, 
        HttpServletResponse response) {
        try {
              String requestPath = request.getRequestURI();
              if (requestPath != null) {
                    if (requestPath.contains("/images/")
                                || requestPath.contains("/scripts/")
                                || requestPath.endsWith(".js")
                                || requestPath.endsWith(".gif")) {
                          response.setHeader("Cache-Control", "max-age=36000");
                    }
              }
        } catch (RuntimeException e) {
              // do nothing except log
              Log.error(this, e);
        }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM