How do you automate Javascript minification for your Java web applications?

前端 未结 11 1989
广开言路
广开言路 2020-12-07 07:02

I\'m interested in hearing how you prefer to automate Javascript minification for your Java web apps. Here are a few aspects I\'m particularly interested in:

  • H
11条回答
  •  猫巷女王i
    2020-12-07 07:38

    I'm really surprised no one mentioned JAWR - https://j-a-w-r.github.io

    It's pretty mature and supports all standard features that are to be expected, and a bit more. Here is how it holds against the OP's excellent criteria.

    How does it integrate? Is it part of your build tool, a servlet filter, a standalone program post-processing the WAR file, or something else?

    It originally did the processing/heavy-lifting at application startup and serving was based on a servlet. Starting with 3.x they added support for integrating at build time.

    Support for JSP and Facelets is provided through a custom JSP tag library to import processed resources. In addition to that, a JS resources loader is implemented which supports loading the resources from static HTML pages.

    Is it easy to enable and disable? It's very unfunny to try and debug a minified script, but it's also useful for a developer to be able to test that the minification doesn't break anything.

    A debug=on option is available to use before application startup, and a custom GET parameter can be specified at individual requests in production to toggle debug mode selectively at runtime for said request.

    Which minifier does it use?

    For JS it supports YUI Compressor and JSMin, for CSS I'm not sure.

    Does it lack any features that you can think of?

    SASS support comes to mind. That said, it does support LESS.

提交回复
热议问题