【问题标题】:Disable caching for ExtJs app禁用 ExtJs 应用程序的缓存
【发布时间】:2016-01-13 10:16:43
【问题描述】:

我们有一个使用 Sencha cmd 5.0.1.231 构建的 ExtJS 5.01 应用程序。

我们面临的问题是浏览器似乎缓存了我们应用程序的旧版本。在为我们的应用程序提供服务时查看 chrome 上的网络流量时,我可以看到 app.js、app.css 文件都附加了 ?_dc={timestamp} 。现在,这告诉我每次发布我的应用程序的新版本(更新此时间戳)时,浏览器都应该获得一个新版本。但似乎有时仍会提供旧版本。

还有什么我需要做的胸围缓存吗?

谢谢

【问题讨论】:

  • 其实应该可以的。这个问题是只针对某些特定的js还是针对所有的?您在生产环境或开发环境中遇到过这个问题吗?
  • 时间戳是针对请求的——每个请求都应该有一个新的时间戳(如果你有一批同时进行,它可能是一样的)。 cache-busting 参数的目的是强制缓存(例如代理服务器)获取新版本。但是,一些缓存服务器不尊重这一点。但是,您看到网络请求这一事实意味着浏览器至少正在尝试获取新版本...
  • @yorlin 似乎发生在生产环境中。开发不是问题,因为我总是在 chrome 中打开开发人员工具栏,我认为这会禁用缓存

标签: javascript caching extjs extjs5 sencha-cmd5


【解决方案1】:

app.json 中将 app.js 的更新属性设置为完整:

{
    // Path to file. If the file is local this must be a relative path from this app.json file.
    "path": "app.js",

    "bundle": true,  /* Indicates that all class dependencies are concatenated into this file when build */

    // If 'update' not specified, this file will only be loaded once, and cached inside
    // localStorage until this value is changed. You can specify:
    //   - "delta" to enable over-the-air delta update for this file
    //   - "full" means full update will be made when this file changes
    "update": "full"
}

禁用 extjs 中的缓存,以便浏览器从服务器获取数据。为此,请添加以下 app.json 文件。

"production": {
    "cache": {
        "enable": false
    }
}

"css": [
    {
        // this entry uses an ant variable that is the calculated
        // value of the generated output css file for the app,
        // defined in .sencha/app/defaults.properties
        "path": "${build.out.css.path}",
        "bundle": true,
        "update": "full"
    }
],

【讨论】:

    【解决方案2】:

    我不明白为什么浏览器“有时”会缓存您的文件,即使默认情况下禁用缓存也是如此。我什至在我的app.js 中加入这种和平的代码,尽可能强制框架使用缓存:

    Ext.Loader.setConfig({
        enabled: true,
        disableCaching: false
    });
    

    在开发过程中,我打开我的 DevTools 并设置 Disable cache (while DevTools is open)。这将不允许 Chrome 缓存文件。

    但可能是在您的app.json 中,您通过设置"update""appcache" 来强制“缓存”到本地存储中。检查您的 localstorage 和您的 app.json 以进行验证。

    【讨论】:

    • 谢谢.. 在我的 app.json 中,我有 appcache:{"cache" : ["index.html"]}。您认为这会导致缓存问题吗?
    • 我建议您生成一个测试应用程序并将其与您已经拥有的应用程序进行比较。开箱即用它不会给您带来任何问题,只有当您对其进行更改时..
    猜你喜欢
    • 2020-07-13
    • 2014-10-26
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 2012-05-13
    • 2016-11-06
    • 2018-01-25
    • 2012-03-26
    相关资源
    最近更新 更多