Maven about build version numbers and compress css,js at build time and append version numbers to these files

Source: Internet
Author: User

Recently responsible for the construction of a project framework, because our side is the back-end team, no professional front-end engineers to support us, I have encountered some front-end problems in this construction process, to share with you. Key sharing points:
    1. The browser can update the cache when the project is built by automatically adding a version number to the Css,js file name to resolve the new live version
    2. Build projects automatically compress CSS,JS resource files for faster response times


To solve the first problem, it is necessary to build a build version number at the time of construction, such as the timestamp at the time of building, just see this plugin on the Internet, configuration information as follows              <plugin>                 <groupId>org.codehaus.mojo</groupId>                 <artifactId>buildnumber-maven-plugin</artifactId>                 <version>1.3 </version>                < executions>                     <execution>                         <phase>validate</phase>                          <goals>                             <goal>create-timestamp</goal >                         </goals>                     </execution>                 </executions>                 <configuration>                     <configuration>                          &LT;FORMAT&GT;{0,DATE,YYYY-MM-DD hh:mm:ss}</format>                         <items>                              <item>timestamp</item>                          </items>                     </configuration>                 </configuration>             </plugiN>
The function of this plugin is to build a version number during the validate phase of the Maven life cycle, when you need this version number, you can be introduced by ${timestamp}, the use of this plugin can be viewed on the official website:/http Mojo.codehaus.org/buildnumber-maven-plugin/index.html
With this version number, the next problem is that the file that introduces Css,js on each page can be copied with a name of XX. {Version}.css,xx.${version}.js file, this will use the second plug-in, look at the following configuration information:
            <plugin>                 <groupId>net.alchim31.maven</groupId>                 <artifactId> yuicompressor-maven-plugin</artifactid>                 <version>1.5.0</version>                 <executions>                     <execution>                          <phase>${assert.compress}</phase>                          <goals>                              <goal>compress</goal>                         </goals>                      </execution>                 </executions>                 <configuration>                     <!--<nosuffix>true</nosuffix>-->                     <suffix>.${timestamp}</suffix>                      <force>true</force>                     <encoding>utf-8</encoding>                     <excludes>                          <exclude>**/*.pack.js</exclude>                         <exclude >**/compressed.css</exclude>                         <exclude>**/*.min.css</exclude>                          <exclude>**/*.min.js</exclude>                     </excludes>                 </configuration>             </plugin>
This plugin not only solves the second compressed Css,js file I wrote above, but also can append the compressed file name to the version number, with this plugin is very good, about this plug-in specific use of information see: http://davidb.github.io/ Yuicompressor-maven-plugin/index.html look at the following build information, note the contents of the box, you can see that jquery-ui.js is compressed to file namejquery-ui.1414549216019.js named files, and this plugin also prints out some other information.

Here, the desired style files are already available, and the next thing to do is to replace them within the file.





Maven about build version numbers and compress css,js at build time and append version numbers to these files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.