2017-06-13 64 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 –