在GWT应用程序中,如何提高性能?

rel="File-List" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"> rel="themeData" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"> rel="colorSchemeMapping" href="file:///C:%5CDOCUME%7E1%5CADMINI%7E1%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml">

GWT性能优化

1.       处理长时间的进程:使用IncrementalCommandCommand

参考文档:

http://code.google.com/docreader/#p(google-web-toolkit-doc-1-5)s(google-web-toolkit-doc-1-5)t(DevGuideDeferredCommand)

2.       使用ImageBundle

a)         什么是ImageBundle

ImageBundlegwt1.4版本之后中最显著的特性,它使得GWT能将多个图片文件合并成一个图片。这样就可以把它们合并到一个可缓存的HTTP 请求中,而不用通过多个请求来一一取得每个图片文件。使用ImageBundle的另外一个好处就是消除了在图像加载并且调整宽度高度时重新调整布局出现的网页内容弹动

b)         如何使用?

参考文档:

http://code.google.com/docreader/#p(google-web-toolkit-doc-1-5)s(google-web-toolkit-doc-1-5)t(DevGuideImageBundles)

 

3.       Servlet容器上(例如Tomcat)使用Filter来实现Caching,参考代码如下:

a)       Filter示例代码:

public class CacheFilter implements Filter{

    

private FilterConfig filterConfig;

 

public void doFilter(ServletRequest request,ServletResponse response,FilterChain filterChain) throws IOException,ServletException{

   HttpServletRequest httpRequest = (HttpServletRequest)request;

   String requestURI = httpReqest.getRequestURI();

   if(requesURI.contains(“.cache.”)){

     HttpServletResponse httpResponse = (HttpServletResponse)response;

     httpResponse.setHeader(“Cache-Control”,”max-age=31536000”);

}

filterChain.doFilter(request,response);

}

 

public void init(FilterConfig filterConfig) throws ServletException{

  this.filterConfig = filterConfig;

}

 

public void destroy(){

  this.filterConfig = null;

}

 

}

 

b)       web.xml文件中配置如下所示:

<filter>

          <filter-name>CacheFilter</filter-name>

            <filter-class>com.gwtapps.server.CacheFilter</filter-class>

</filter>

<filter-mapping>

            <filter-name>CacheFilter</filter-nam>

            <url-pattern>/*.html</url-pattern>

</filter-mapping>

<filter-mapping>

            <filter-name>CacheFilter</filter-nam>

            <url-pattern>/*.png</url-pattern>

</filter-mapping>

 

4.       Servlet容器上(例如Tomcat)使用Filter来实现Compression,参考代码如下:

a)       server.xml文件中做如下设置:

<Connector port=”8080” redirectPort=”8443” acceptCount=”20” compression=”on”/>

 

b)       Filter示例代码:

public class GZIPFilter implements Filter {

 

    private FilterConfig filterConfig;

 

  public void doFilter(ServletRequest request,ServletResponse response,FilterChain filterChain) throws IOException,ServletException{

    HttpServletRequest httpRequest = (HttpServletRequest)request;

    //skip gzipped files

    String requestURI = httpRequest.getRequestURI();

    if(!requestURI.endsWith(“.gz”)){

      //check for zip support

      String acceptEncoding = httpRequest.getHeader(“accept-encoding”);

      if(acceptEncoding != null && acceptEncoding.indexOf(“gzip”) != -1){

                   // forward to .gz file

        try{

          RequestDispatcher rd=

filterConfig.getServletContext().getRequestDispatcher(requestURI + “.gz”);

                 rd.forward(request,response);

                 return;

}

catch(ServletException e){

  //continue;

}

}

}

filterChain.doFilter(request,response);

}

 

public void init(FilterConfig filterConfig) throws ServletException{

  this.filterConfig = filterConfig;

}

 

public void destroy(){

  this.filterConfig = null;

}

}

 

c)       web.xml文件中配置如下所示:

<filter>

            <filter-name>GZIPFilter</filter-name>

            <filter-class>com.gwtapps.server.GZIPFilter</filter-class>

</filter>

<filter-mapping>

            <filter-name>GZIPFilter</filter-name>

            <url-pattern>*.html</ url-pattern >

</filter-mapping>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值