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

前端 未结 11 1963
广开言路
广开言路 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条回答
  •  [愿得一人]
    2020-12-07 07:19

    I tried two ways:

    1. using a servlet filter. When in production mode, the filter is activated and it compress any data bounded to URL like *.css or *.js
    2. using maven and yuicompressor-maven-plugin; the compression is perfomed una-tantum, (when assembling the production war)

    Of course the latter solution is better since it does not consume resources at runtime (my webapp is using google app engine) and it doesn't complicate your application code. So assume this latter case in the following answers:

    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?

    using maven

    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.

    you activate it only when assemblying the final war; in development mode you see the uncompressed version of your resources

    Does it work transparently, or does it have any side effects (apart from the ones inherent in minification) that I have to consider in my day-to-day work?

    absolutely

    Which minifier does it use?

    YUI compressor

    Does it lack any features that you can think of?

    no, it is very complete and easy to use

    What do you like about it?

    it is integrated with my favourite tool (maven) and the plugin is in the central repository (a good maven citizen)

提交回复
热议问题