Hi,
Granule is a compressor tool to unify all CSS and JS resources on Java Web app. It supports many compression techniques like cssfastmin, jsfastmin, combine only and closure-compile.
Your use is so simple, first download from repository (at Github have many forks with bugs fix, but them aren’t synchronized with main version ¬¬):
On your application, put granule.jar in ‘WEB-INF/lib’ folder and put granule.properties in WEB-INF folder.
On all your pages, you’ll declare the import instruction below:
1 |
<%@ taglib prefix="g" uri="http://granule.com/tags" %> |
Below, an example of Granule usage in your JSP pages:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<%@ taglib uri="http://granule.com/tags" prefix="g" %> <!DOCTYPE html> <html> <head> <g:compress> <link href="<%=request.getContextPath()%>/css/bootstrap.min.css" /> <link href="<%=request.getContextPath()%>/css/bootstrap-responsive.min.css"/> </g:compress> <g:compress> <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ // do something after page is ready. }); </script> </g:compress> </head> <body> <!-- all page content... --> </body> </html> |
Warning! Sometimes, on first request, the combined.js and/or combined.css can throws “not found” and not loading on client side, to fix this, you can use this ugly scriplet to force full path for combined CSS/JS files:
1 |
<%=request.getContextPath()%> |
Bye.