JavaWeb开发分享:WRO

WRO是为了提高Java Web前端的性能而出现的技术,简单来说它的功能就是压缩(processor)和组合文件(group),减少文件传输次数和大小。

There are countless articles related to web performance. The most comprehensive one is performed by researchers from Yahoo. They have identified a number of best practices for making web pages fast. You can find the details here. They have created a tool called YSlow: which analyzes web pages and tells you why they're slow based on the rules for high performance web sites. YSlow is a Firefox add-on integrated with the popular Firebug web development tool.

The aim of wro4j project is to help application developed on java platform to address a couple of those problems described by Yahoo research. More, exactly it is about "Minimize HTTP Requests" and "Gzip Components".

为了使用WRO,需要在web.xml加入filter,在web应用中加入wro4j-core.jar,在web-int文件夹下面加入wro配置信息。

WRO configuration in web.xml


  WebResourceOptimizer
  
    ro.isdc.wro.http.WroFilter
  


  WebResourceOptimizer
  /wro/*


WRO configuration in maven pom.xml

        
        
            ro.isdc.wro4j
            wro4j-core
        

WRO properties and xml

debug=false
managerFactoryClassName=ro.isdc.wro.manager.factory.ConfigurableWroManagerFactory
preProcessors=cssUrlRewriting,semicolonAppender,cssMinJawr
gzipResources=false
encoding=UTF-8
ignoreMissingResources=false
postProcessors=cssVariables,jsMin
uriLocators=servletContext,uri,classpath

more details: https://code.google.com/p/wro4j/wiki/ResourceTypes https://code.google.com/p/wro4j/wiki/AvailableProcessors

WRO xml file



    
        classpath:META-INF/resources/webjars/jquery/1.9.0/jquery.min.js
        classpath:META-INF/resources/webjars/bootstrap/3.0.2/js/bootstrap.min.js
        classpath:META-INF/resources/webjars/jquery-cookie/1.3.1/jquery.cookie.js
        /scripts/script.js
    

最后在jsp文件中把要引用的javascript链接改成如下:

  

 
  

Note: 

1. css文件类似,把css group起来,然后引入group.css

2. wro properties文件可以不用自己写,在maven中有好插件: wro4j-maven-plugin

你可能感兴趣的:(Java,Web,Java)