项目作者: deniskiriusin

项目描述 :
CSS and JavaScript concatenation tool
高级语言: Java
项目地址: git://github.com/deniskiriusin/combinatorius.git
创建时间: 2016-01-21T11:28:49Z
项目社区:https://github.com/deniskiriusin/combinatorius

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Combinatorius — CSS and JavaScript concatenation tool


Maven Central

Demo: http://combinatorius.dkiriusin.com

Table of contents

Key features

  • Combined files to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining all CSS into a single stylesheet.
  • Local caching of the combined files for even better response times.
  • Appropriate Expires and Cache-Control headers to help browser with conditional requests.
  • ETag support to determine whether the component in the browser’s cache matches the one on the origin server.
  • Gzip compression to reduce response times by reducing the size of the HTTP response.
  • YUI Compressor support
  • Fingerprinting a.k.a static web resources versioning.
  • Themes support (set via URL parameter or cookies).
  • Flexible directory structure.
  • Simple configuration.

Quick start

The library is available from the Central Repository and easy to setup.

1. Add dependencied
  1. <dependency>
  2. <groupId>com.dkiriusin</groupId>
  3. <artifactId>combinatorius</artifactId>
  4. <version>1.0.60</version>
  5. </dependency>

You have to add YUI Compressor as well in case you want to take advantage of YUI minification.

  1. <dependency>
  2. <groupId>com.yahoo.platform.yui</groupId>
  3. <artifactId>yuicompressor</artifactId>
  4. <version>2.4.8</version>
  5. </dependency>
2. Register new servlet
  1. <servlet>
  2. <servlet-name>Combinatorius</servlet-name>
  3. <servlet-class>com.dkiriusin.combinatorius.CombinatoriusServlet</servlet-class>
  4. </servlet>
  5. <servlet-mapping>
  6. <servlet-name>Combinatorius</servlet-name>
  7. <url-pattern>/combo/*</url-pattern>
  8. </servlet-mapping>
3. Create combinatorius.properties file and place it in the Classpath
  1. #---------------------#
  2. # required properties #
  3. #---------------------#
  4. # root CSS directory
  5. prop.css.dir = /var/lib/tomcat7/webapps/my_project/css
  6. # cached CSS directory
  7. prop.css.cache.dir = /var/lib/tomcat7/webapps/my_project/css_cache
  8. # root JS directory
  9. prop.js.dir = /var/lib/tomcat7/webapps/my_project/js
  10. # cached JS directory
  11. prop.js.cache.dir = /var/lib/tomcat7/webapps/my_project/js_cache
  12. #---------------------#
  13. # optional properties #
  14. #---------------------#
  15. # themes root directory
  16. prop.themes.dir = /var/lib/tomcat7/webapps/my_project/themes
  17. # Cache-Control: s-maxage directive (31536000 by default)
  18. prop.s-maxage = 31536000
  19. # Cache-Control: max-age directive (31536000 by default)
  20. prop.max-age = 31536000
  21. # Enables gzip compression (true by default)
  22. prop.isCompressionEnabled = true
  23. # Enables YUI compressor (true by default)
  24. prop.isYUICompressorEnabled = false
  25. # Insert line breaks in output after the specified column number (-1 by default)
  26. prop.YUI.CSSCompressor.linebreakpos = -1
  27. # Splits long lines after a specific column (100 by default)
  28. prop.YUI.JavaScriptCompressor.linebreak = 100
  29. # Minify only, do not obfuscate (false by default)
  30. prop.YUI.JavaScriptCompressor.nomunge = false
  31. # verbose output (false by default)
  32. prop.YUI.JavaScriptCompressor.verbose = false
  33. # Preserve unnecessary semicolons (such as right before a '}') (false by default)
  34. prop.YUI.JavaScriptCompressor.preserveAllSemiColons = true
  35. # Disable all the built-in micro optimizations (true by default)
  36. prop.YUI.JavaScriptCompressor.disableOptimisations = true
  37. # Define files to be omitted of minification ('.*\.min\.(js|css)$' by default)
  38. prop.YUI.OmitFilesFromMinificationRegEx = .*\.min\.(js|css)$

Combinatorius reads all CSS and JavaScript resources from prop.css.dir and prop.js.dir directories recursively in alphabetic order and caches them in prop.css.cache.dir and prop.js.cache.dir directories respectively.

  1. dir/
  2. ├── css/
  3. ├── main.css
  4. ├── layout.css
  5. ├── css_cache/
  6. ├── 5f87023f44e39b9e735111b02bd7a40e.css.cmb.gzip
  7. ├── js/
  8. ├── jquery-1.11.3.min.js
  9. └── jquery-ui.js
  10. └── js_cache/
  11. └── e04df45335c9227366384ba3994663ec.js.cmb.gzip

Minified and compressed content sent back to client with all necessary HTTP headers set. Resources corresponding the regular expression prop.YUI.OmitFilesFromMinificationRegEx are not minified by YUI Compressor.

CSS themes support

CSS theme represents prop.themes.dir sub-directory with one or more CSS resources. For example prop.themes.dir/green/theme.css. The name of the theme must match the name of the sub-directory and can be set via theme URL parameter or combinatorius.theme Cookies value.

/combo/&type=css&theme=green

Additional resources

It might be useful for testing purposes or with rarely used resources that should not be included in to main assembly by default.

/combo/&type=js&resources=extra_js/extra1.js,extra_js/extra2.js

JSP tag

It is recommended to use JSP tag in order to generate a valid Combinatorius URL. One tag for CSS and one for JavaScript respectively. The only mandatory attributes are type and path.

  1. <%@ taglib uri="https://github.com/deniskiriusin/combinatorius" prefix="cb" %>
  2. <cb:combo type="css" path="/combo">
  3. <jsp:attribute name="theme">blue</jsp:attribute>
  4. <jsp:attribute name="csv_resources">extra_css/extra1.css,extra_css/extra2.css</jsp:attribute>
  5. </cb:combo>
  6. <cb:combo type="js" path="${path}"></cb:combo>

Using JSP tag has some additional benefits like static web resources versioning for aggressive caching (cache busting).

/combo/&type=js&v=1465737376000

Contributing

Pull requests are welcome.