Struts 2集成Dojo性能优化

2010年6月10日 | 标签: ,

最近部署一个应用,上线后感觉页面访问比较慢。检查发现每个页面都要重复下载一些Dojo的JS,而且被设置不被浏览器缓存。检查发现应用是用的Struts 2集成的Dojo, Dojo文件是由struts filter动态从struts-core中加载。考虑之后决定把struts中的Dojo这样的静态资源都提取出来于Web服务器直接提供,并且设置压缩传输及Cache策略。一切完成之后,世界又变的很美好。

Instructions for improving the performance of dojo 0.4.2 in Struts 2.0.9:
>
> $resources$ is assumed to be your web resources directory
>
> 1. First, configure struts to serve the static files directly from
> $resources$/struts instead of from within struts-core-2.0.9.jar:
>    a. extract struts2-core-2.0.9.jar/org/apache/struts2/static/* to
> $resources$/struts/
>   b. edit struts.properties and set struts.serve.static=false
>   c. also extract the javascript and css files from
> struts2-core-2.0.9.jar/templates/* to $resources$/struts/ as this will
> be helpful later
>       eg. $resources$/struts/ajax/dojoRequire.js
>
> Confirm that your application still works before proceeding. It’s
> essential that resources are loaded from the directory rather than the jar.
>
> 2. Download the source of dojo 0.4.2. You won’t need to modify it. The
> download location doesn’t matter. We assume it’s in release-0.4.2/
>
>  > svn export http://svn.dojotoolkit.org/dojo/tags/release-0.4.2
>
> This is almost identical to the version bundled with struts2.0.9.
>
> 3. Use an editor to create a dojo custom profile as the file
> release-0.4.2/buildscripts/profiles/struts2.profile.js. This file
> defines which dojo resources you use directly. Essentially it specifies
> which code will be included in dojo.js. An example that includes almost
> everything is provided at the end of this email.
>
> 4. Copy the struts widgets into the dojo directory so they can be
> included within dojo.js. That is, copy $resources$/struts/dojo/struts/*
> to release-0.4.2/struts.
> This is the directory that contains the widget and widgets
> subdirectories, css and some images.
>
> 5. Build dojo using ant. This will create a new dojo.js file:
>
> > cd release-0.4.2/buildscripts
> > ant -Dprofile=struts2 -Dstrip_and_compress=true clean release
> intern-strings strip-resource-comments
>
> (You may be asked to run it twice).
>
> Pay some attention to the build process. In particular, note whether it
> finds the struts widgets and ‘internalises’ the related resources. If
> not, see Step 4. You’ll probably notice a lot of things are included
> that you don’t need. That will be helpful later for optimizations.
> Some errors will occur while stripping the comments but these are ok.
>
> 6. When the build process completes the release directory will contain
> all the files you need. The content of the release directory can be
> copied over the top of $resources$/struts/dojo. You’ll notice it’s
> almost exactly the same as the original, although dojo.js is probably
> larger.
>
> It’s okay to delete the demo, test and release subfolders before copying
> to your application. The src subfolder must be distributed with your
> application as it contains images used by dojo.
>
> 7. Clear your browser cache and test your application again. You should
> note the larger dojo.js file being loaded and significantly fewer
> requests for resources by dojo  Hopefully it’s also a lot faster.
>
> That’s it. Now you can go back and optimize the profile by removing
> resources you don’t need. There’s examples in the profiles directory.
> Repeat the build/test process to find the right balance.
> I also recommend editing $resources$/struts/ajax/dojoRequire.js to
> remove the reference to the Editor2 if you don’t use this as it’s a
> very,very heavy-weight resource.

相关文章:

  1. 开启apache mod_deflate支持内容压缩传输,提升网站性能
  2. Web应用合理的Cache-Control,细节决定成败
  3. P3P Header
  4. WebSphere Web Server配置方式选择
  5. SLES 10 Apache升级
目前还没有任何评论.