3

I m trying to gzip js & css files at build time using wro4j Maven (invoked via m2e-wtp - using Eclipse Luna), but it is not working. I've tried with 1.7.5, 1.7.7 versions.

Below is config I've:

wro.xml:

<plugin>
    <groupId>ro.isdc.wro4j</groupId>
    <artifactId>wro4j-maven-plugin</artifactId>
    <executions>
        <!-- JS minification -->
        <execution>
            <id>js-minify</id>
            <phase>compile</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <debug>true</debug>
                <targetGroups>angular-deps,app-bundle</targetGroups>
                <minimize>true</minimize>
                <!-- provide Google Closure compiler options using custom factory --><wroManagerFactory>com.manikanta.wro4j.maven.CustomWroManagerFactory</wroManagerFactory>
                <groupNameMappingFile>${basedir}/src/main/webapp/js-min/group-mapping.properties</groupNameMappingFile>
                <ignoreMissingResources>false</ignoreMissingResources>
                <gzipEnabled>true</gzipEnabled>
            </configuration>
        </execution>

        <!-- CSS minification -->
        <execution>
            <id>css-minify</id>
            <phase>compile</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <targetGroups>styles</targetGroups>
                <minimize>true</minimize>
                <ignoreMissingResources>true</ignoreMissingResources>
                <groupNameMappingFile>${basedir}/src/main/webapp/css-min/group-mapping.properties</groupNameMappingFile>
            </configuration>
        </execution>
    </executions>

    <configuration>
        <contextFolder>${basedir}/src/main/webapp/</contextFolder>
        <!-- <destinationFolder>${project.build.directory}/${project.build.finalName}</destinationFolder> -->
        <destinationFolder>${basedir}/src/main/webapp/bundle</destinationFolder>
        <jsDestinationFolder>${basedir}/src/main/webapp/js-min</jsDestinationFolder>
        <cssDestinationFolder>${basedir}/src/main/webapp/css-min</cssDestinationFolder>
        <wroFile>${basedir}/src/main/resources/wro.xml</wroFile>
        <extraConfigFile>${basedir}/src/main/resources/wro.properties</extraConfigFile>
        <wroManagerFactory>ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory</wroManagerFactory>
        <ignoreMissingResources>false</ignoreMissingResources>
        <incrementalBuildEnabled>true</incrementalBuildEnabled>
    </configuration>
</plugin>

wro.properties:

# General Configuration
debug=true

gzipResources=true
gzipEnabled=true

#List of preProcessors
preProcessors=googleClosureSimple
#List of postProcessors
postProcessors=yuiCssMin

# naming strategy
hashStrategy=CRC32
namingStrategy=hashEncoder

sourceMapsDestinationFolder=d:/__sourcemaps

incrementalBuildEnabled=true

parallelPreprocessing=true
parallelProcessing=true

I tried both gzipResources and gzipEnabled (it is not clear which once to use for build time solution!).

Can someone tell me how to do gzip at build time? Thanks.

manikanta
  • 8,100
  • 5
  • 59
  • 66
  • I asked for https://issues.apache.org/jira/browse/MWAR-354 because I didn't see a way of doing this in vanilla maven, and it ought to be there. – David Bullock Aug 28 '15 at 05:54

2 Answers2

1

I've written a simple Maven plugin to just do this: gzip JS & CSS files.

https://github.com/manikantag/em-maven-resource-optimizer

manikanta
  • 8,100
  • 5
  • 59
  • 66
0

The maven plugin is responsible for producing plain minimimized resources. It is not supposed to produce gzipped content. In order to serve gzipped content, you should use a specialized filter or configure your container to handle the gzip operation.

Alex Objelean
  • 3,893
  • 2
  • 27
  • 36
  • 1
    Oh... Now that Tomcat 8 supports pre-gzip'ed resource (http://tomcat.apache.org/tomcat-8.0-doc/default-servlet.html), now this feature is makes more sense, I think. Is there any way we can achieve the build time gzipping using the wro4j runtime gzipping functionality? Thanks. – manikanta Nov 04 '14 at 00:36
  • There is ro.isdc.wro.http.GzipFilter implementation which is could help you. You can also use similar implementation which is provided by spring (don't recall the class name). – Alex Objelean Nov 04 '14 at 07:48