12 Replies Latest reply on Apr 12, 2010 9:59 AM by Jay Balunas

    Compress custom-dependencies.js

    Andreas Panagiotidis Novice

      Hi,

       

      I use Maven to merge my JavaScript and CSS files.

       

      <artifactId>maven-resource-dependency-plugin</artifactId>
      <groupId>org.richfaces.cdk</groupId>
      <version>3.3.2.SR1</version>

       


      The custom-dependencies.js and custom-dependencies.xcss get created but the do not get compressed (minified , obfuscated)

       

      I would like to compress them at compile-time, in order to save some load from the web-server.

       

      a) Is it possiple to do this with the existing plugin?


      b) If it is not possible, I plan to implement it, asap.

      What would you think is better to add in the maven-resource-dependency-plugin?

      1. create in the <configuration> a node (like the <scriptIncludes>) called <compressed> (boolean)

      2. create a goal called compress

       

      Thanks,

      Andreas

        • 1. Re: Compress custom-dependencies.js
          Anton Belevich Novice

          Hi Andreas,

           

               Unfortunally Richfaces RD plugin doesn't support compress feature.  I think it will be great if you contribute this necessary feature. As form me I think this is should be a goal "compressed". Thanks for participation! 

          • 2. Re: Compress custom-dependencies.js
            Andreas Panagiotidis Novice

            Thanks Anton,

             

            I implement at the moment compression as a goal.

             

            As soon as its ready, I will submit the code and notify you.

            • 3. Re: Compress custom-dependencies.js
              Anton Belevich Novice

              apanag wrote:

               

              Thanks Anton,

               

              I implement at the moment compression as a goal.

               

              As soon as its ready, I will submit the code and notify you.

                   ok

              • 4. Re: Compress custom-dependencies.js
                Andreas Panagiotidis Novice

                Is it possible or do you know how to: define the execution order of goals in maven?

                 

                I have built the "compress" goal.

                 

                I just want for validation and easy of use to make sure that the component should always call first the assembly and then compile.

                Otherwise in case the user set the followin: (meaningless but possible from a user):

                 

                <goals>
                    <goal>compress</goal>
                    <goal>assembly-resources</goal>
                </goals>

                 

                I get an exception, since naturally the packages do not exist.

                • 5. Re: Compress custom-dependencies.js
                  Anton Belevich Novice

                  apanag wrote:

                   

                  Is it possible or do you know how to: define the execution order of goals in maven?

                   

                  I have built the "compress" goal.

                   

                  I just want for validation and easy of use to make sure that the component should always call first the assembly and then compile.

                  Otherwise in case the user set the followin: (meaningless but possible from a user):

                   

                  <goals>
                      <goal>compress</goal>
                      <goal>assembly-resources</goal>
                  </goals>

                   

                  I get an exception, since naturally the packages do not exist.

                       Goal may be bound to the different build phases. "assembly-resources" goal runs on "generate-resources" phase  so "compress" goal could be run on "process-resources" which invoke right after it.

                  1 of 1 people found this helpful
                  • 6. Re: Compress custom-dependencies.js
                    Ilya Shaikovsky Master

                    thread moved to development in order to discuss possible contribution.

                    • 7. Re: Compress custom-dependencies.js
                      Andreas Panagiotidis Novice

                      Current plugin:

                       

                      The maven-resource-dependency-plugin creates two files: custom-dependencies.js and custom-dependencies.xcss

                      I guess you already know that those are the project's javascript and css files packaged together.

                       

                      My goal:

                       

                      Compress (minify) those "packaged files" : (the custom-dependencies.js and custom-dependencies.xcss)

                       

                      What I did:

                       

                      1. Copied the YuiCompressorMojo.java in the org.richfaces.cdk.rd.mojo, renamed it to YuiCompressorMojoPackage

                       

                      2. Adapted the YuiCompressorMojoPackage, so it reads and minifies the custom-dependencies.js and custom-dependencies.xcss


                      /**
                      * Apply compression on JS and CSS (using YUI Compressor).
                      *
                      * @goal compress
                      * @phase process-resources
                      */
                      public class YuiCompressorMojoPackage extends AbstractMojo {

                      ....

                      }

                       

                       

                       

                      Now, my pom that uses the maven-resource-dependency-plugin looks like:

                       

                      <executions>
                                          <execution>
                                              <configuration>

                       

                                                  <webSourceDirectory>${basedir}/WebContent/</webSourceDirectory>

                       

                                                  <outputResourceDirectory>${project.build.outputDirectory}</outputResourceDirectory>

                       

                                                  <afterScriptIncludes> ... </afterScriptIncludes>

                       

                                                  <afterStyleIncludes>..... </afterStyleIncludes>

                       

                                                  <gzip>false</gzip>
                                                  <nosuffix>true</nosuffix>
                                                  <nomunge>false</nomunge>

                       

                                              </configuration>

                       

                                              <goals>
                                                  <goal>assembly-resources</goal>
                                                  <goal>compress</goal>
                                              </goals>


                                          </execution>

                       

                       

                      So, after the execution the assemblied resources get compressed.

                       

                      What do you think?

                      • 8. Re: Compress custom-dependencies.js
                        Jay Balunas Master

                        Hi Andreas,

                         

                        I'll take a look for your contributor agreement.  We get many random contributor requests, and if I'm not aware of a developer with a contribution I do not approve them.  Moving this to development thread was a good idea.

                         

                        Your update seems interesting, and I have some comments and questions.

                         

                        What is the license of YuiCompressorMojo.java?  Depending on license we can not just rename and include in our distribution. 

                         

                        I like the feature though, and the idea so well just need to figure that out.

                         

                        I would recommend creating a RF jira to cover this feature request and contribution.  We'll be able to track it easier, and work through the questions.

                         

                        Thanks so much for taking the time and effort to create this!!

                         

                        Jay

                        • 9. Re: Compress custom-dependencies.js
                          Andreas Panagiotidis Novice

                          Hi Jay,

                           

                          the CSSCompressor is part of the YUI package and it is already included in RichFaces. It is GNU 2.1 (Lesser).

                          It is no problem to change it, according to the license.

                           

                          Adding the feature to Jira:

                          I could not see any component that matches the scope of this feature.

                           

                          For example:

                          build: it is about building RF , so not in here

                          CDK: the feature is not part of CDK

                           

                          In which Jira component do you think I should add it?

                           

                          andreas

                          • 10. Re: Compress custom-dependencies.js
                            Jay Balunas Master

                            Andreas Panagiotidis wrote:

                             

                            Adding the feature to Jira:

                            I could not see any component that matches the scope of this feature.

                             

                            For example:

                            build: it is about building RF , so not in here

                            CDK: the feature is not part of CDK

                             

                            In which Jira component do you think I should add it?

                             

                            andreas

                             

                            I would use "core" for now, we can adjust as needed.  I take a look in more detail when I can.

                            • 11. Re: Compress custom-dependencies.js
                              Andreas Panagiotidis Novice

                              https://jira.jboss.org/jira/browse/RF-8588

                               

                              I made an entry for this feature in Jira. Could you please read the description and add your comments ?

                              • 12. Re: Compress custom-dependencies.js
                                Jay Balunas Master

                                Thanks!!

                                 

                                We are about to release 3.3.3.F, and will then be-able to focus on new ideas and plans for 4.0.0.  This one included.