基於maven插件的緩存控制插件

asset-cache-control

 github源碼及下載地址https://github.com/StruggleBird/asset-cache-controljavascript

 

 

基於maven插件的緩存控制工具,經過修改資源url的請求參數,好比在url後面添加版本號或者時間戳的形式,來有效的防止瀏覽器緩存。

目前該功能可用於避免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>

  

其餘配置:

  • resourcesURL:定義資源URL前綴
  • suffixs:文件後綴,容許多個,用於聲明哪些後綴的文件能夠作打版本操做,默認支持jsp、html、htm、ftl,若是填寫則覆蓋默認文件後綴,只會處理指定的文件後綴
  • version:版本號,給資源url添加的版本號,若是爲空,則打上當前時間戳
  • resourcesDirs:待處理的資源目錄,容許多個。若是指定,則只打當前指定目錄下面的文件到靜態資源包中

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">
相關文章
相關標籤/搜索