In the previous chapter we introduced, from the browser to the server to get resources, you can use gzip to get the browser is compressed resources to reduce network download time, then we can consider from the source, that is, we from the source (resources themselves) to make the resources as small as possible.
Method Of course is some, general resources have css,js,image, our idea is, for css,js, we use yui-compressor to compress it, for image, we will sprite them into a single large map to reduce the number of network requests.
Yui-compressor, I believe a lot of people are not unfamiliar, it can be dedicated to compress Css,js, the general will remove the comments, blank lines, merging the semantics of similar lines, etc., here is not to repeat. We used maven for the build distribution, so we used Maven's Yui-compressor plugin to do the job.
The specific configuration is as follows:
Just add a <plugin> to the <plugins> of our pom file as follows:
... <plugin> <groupId>net.alchim31.maven</groupId> <ARTIFACTID&G T;yuicompressor-maven-plugin</artifactid> <version>${yui-compress-version}</version> < Executions> <execution> <phase>prepare-package</phase > <goals> <goal>compress</goal> </go
Als> <configuration> <nosuffix>true</nosuffix> <JSWARN>FA lse</jswarn> </configuration> </execution> &L T;/executions> </plugin> <plugin> <groupid>org.apache.maven. Plugins</groupid> <artifactid>maven-war-plugin</artifactId> <VERSION>${PLUGIN.WAR.VERSION}</VERSION&G
T <configuration> <warsourceexcludes>js/**, Css/**</warsourceexcludes > </configuration> </plugin> </plugins>
And then when we run it, we automatically see that the compression is done at the end of the compile, unit test, and finally in the package, because our yuicompressor-maven-plugin is defined before Maven-war-plugin:
From here we can significantly see that most of the JS resource files have varying degrees of compression.