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:
- 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
- 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> <FORMAT>{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