2017-06-13 47 views
1

我們使用的是Extjs 6,我們使用的是sencha cmd來構建我們的應用程序。ExtJS 6 app.js在新產品發佈後不會更新

我們正面臨一個問題。每次我們發佈我們的應用程序的生產版本像6.3到6.4時,捆綁的app.js沒有得到更新,瀏覽器從(from disk cache)獲取該文件。所以每次我們必須告訴我們的用戶,請在獲得新版本後清除瀏覽器的緩存。 That's annoying

這是我的app.json文件。

"output": { 
     "base": "${workspace.build.dir}/${build.environment}/${app.name}", 
     "page": "index.html", 
     "manifest": "${build.id}.json", 
     "js": "${build.id}/.js", 
     "appCache": { 
      "enable": false, 
      "update": "full" 
     }, 
     "resources": { 
      "path": "${build.id}/resources", 
      "shared": "resources" 
     } 
    }, 
"production": { 
     "output": { 
      "appCache": { 
       "enable": false, 
       "path": "cache.appcache" 
      } 
     }, 
...... 
"cache": { 
      "enable": false 
     } 
... 
+0

請參閱https://stackoverflow.com/a/44280812/2935802 – Sudhakar

回答

1

我已經找到解決方案:

"js": [ 
     { 
      "path": "app.js", 
      "bundle": true, 
      "includeInBundle": false 
     } 
    ], 
..... 
"output": { 
     "base": "${workspace.build.dir}/${build.environment}/${app.name}", 
     "page": "index.html", 
     "manifest": "${build.id}.json", 
     "js": "${build.id}/app_${app.version}.js", 
     "appCache": { 
      "enable": false, 
      "update": "full" 
     }, 
     "resources": { 
      "path": "${build.id}/resources", 
      "shared": "resources" 
     } 
    }, 
.... 

這將不包括app.js文件在生產建設和創造新app.js文件,版本在最後追加到它喜歡:app_6.4.js

2

以下是爲您解決問題兩個選項:

自定義app.js文件名

 { 
      "production": { 
       "output": { 
        "js": "${build.id}/app_${build.timestamp}.js" 
       }, 
       "cache": { 
        "enable": true 
       }, 
       "js": [ 
        { 
         "path": "${build.id}/app.js", 
         "bundle": true, 
         "includeInBundle": false 
        } 
       ], 
      "output": { 
      "base": "${workspace.build.dir}/${build.environment}/${app.name}", 
      "page": "index.html", 
      "manifest": "${build.id}.json", 
      "js": "${build.id}/app_${app.version}.js", 
      "appCache": { 
       "enable": false, 
       "update": "full" 
      }, 
      "resources": { 
       "path": "${build.id}/resources", 
       "shared": "resources" 
      } 

     } 
    } 

有了這個,你每次你建立你的應用程序爲新的文件名時app.js

添加靜態緩存參數

{ 
     "production": { 
      "loader": { 
       "cache": "${build.timestamp}" 
      }, 
      "cache": { 
       "enable": true 
      } 
     } 
    } 

有了這個解決方案ExtJS的會追加一個?_dc=12345678參數來app.js請求。這個參數在你的下一次構建之前保持不變。

+0

我已經嘗試了兩種方法。首先:它試圖在應用程序中查找確切的文件名,以便發生錯誤,並在第二個選項中:它將「_dc」添加到請求,但仍然瀏覽器緩存該文件,所以根本不工作。 –

+0

你使用哪個版本的Sencha Cmd?我已經用版本6.2.2.36(ExtJs 6.2.1)試了一下。經典或現代工具包? –

+0

@RonakPatel這裏是我的完全簡化的'app.json':https://gist.github.com/astepin/fb1e95f753e9057570cf86e79179a48f –