主要是看上有JSP Tag很好整合。
功能如下
- Combine and compresses JS and CSS using different methods: on fly or in build process, CSS and JS fast compression or more sophisticated Google Closure compression, or just simple file combining.
- No-lock in solution. The tag just put around existing scripts. The tag can be turn on/off on the different levels: page and application.
- Debug and production modes.
- Calculate dependencies using Closure Library package/namespace system.
- Can automatically choose optimization methods.
- Multiple combinations of JS/CSS even with different compression methods on one page.
- Support JSP includes.
- Several types of cache, memory and file.
- Automatically regenerates the bundle if you modify an included file.
- Proxy-friendly GZip support.
- Rewrites relative URLs in your CSS files.
- JSP, JSF, Grails integration.
- Multiple loggers support (SLF4J, Log4J, Apache Logger)
- Can be setup to preserve license headers of JS libraries.
- JDK1.5 and higher even for Google Closure Compiler.
安裝
- 將Granule的jar檔放入你專案的library
- 在要套用的jsp網頁上面放置以下tag
- <%@ taglib uri="http://granule.com/tags" prefix="g" %>
- 配置web.xml檔
網頁配置
透過g:compress tag可以將範圍內所包含的js或inline js打包成一包。
執行結果
其他功能
- 加入設定檔
看了一下TagCacheFactory原始碼有三種設定檔,可以讓我們切換專案模式。
備註: 如果更新properties要重開tomcat才有效
public final static String PRODUCTION_PATH = "/WEB-INF/granule.properties";
public final static String DEBUG_PATH = "/WEB-INF/granule.debug.properties";
public final static String DEVELOPER_PATH = "/WEB-INF/granule.developer.properties";
2. 啟用檔案快取
# cache - type of cache
# values:
# memory - all combined and compressed allocated in the server memory
cache=disk
#cache=memory
之後會在專案路徑\build\web\granulecache\之下產生實體檔案,如果你的js有修改,檔案的修改日期也會變更的
沒有留言:
張貼留言
留個話吧:)