github源碼及下載地址: https://github.com/StruggleBird/asset-cache-controljavascript
目前該功能可用於避免js、css、image 三種文件類型緩存css
1.添加插件asset-cache-control 到pom文件中:html
<build> <plugins> <plugin> <groupId>org.zt</groupId> <artifactId>asset-cache-control</artifactId> <version>1.0.0</version> <executions> <execution> <id>version</id> <phase>prepare-package</phase> <goals> <goal>version</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
2.執行命令: 執行maven命令,用來替換工程中全部的動態文件中引用的靜態資源URL路徑。java
打版本命令: mvn asset-cache-control:version
打靜態資源到獨立war包命令:mvn asset-cache-control:package
該命令會自動添加版本號或者時間戳到靜態資源URL後面,自動添加靜態資源域名在url前面(若是有配置靜態資源域名),例如 :jquery
原始:git
<script type="text/javascript" src="/javascripts/jquery-1.10.2.min.js"></script> <link href="/css/bootstrap.min.css" rel="stylesheet">
執行後效果:github
版本號模式bootstrap
<script type="text/javascript" src="http://res.github.com/javascripts/jquery-1.10.2.min.js?v=1.1.0"></script> <link href="http://res.github.com/css/bootstrap.min.css?v=1.1.0" rel="stylesheet">
時間戳模式瀏覽器
<script type="text/javascript" src="http://res.github.com/javascripts/jquery-1.10.2.min.js?v=14298124845"></script> <link href="http://res.github.com/css/bootstrap.min.css?v=14298124845" rel="stylesheet">