0

每当我进行新部署时,我都会面临缓存问题,更改不会自动反映。总是我必须去浏览器设置并清除缓存。每当我进行新部署时,有没有办法自动处理这个问题。

4

3 回答 3

1
requirejs.config({
// Path mappings for the logical module names
         paths: {
                'knockout': 'libs/knockout/knockout-3.4.0',
                'jquery': 'libs/jquery/jquery-3.1.1.min',
                'jqueryui-amd': 'libs/jquery/jqueryui-amd-1.12.0',
                'promise': 'libs/es6-promise/es6-promise.min',
                'ojs': 'libs/oj/v3.2.0/min',
                'ojL10n': 'libs/oj/v3.2.0/ojL10n',
                'ojtranslations': 'libs/oj/v3.2.0/resources',
                'signals': 'libs/js-signals/signals.min',
                'text': 'libs/require/text',
                'hammerjs': 'libs/hammer/hammer-2.0.8.min',
                'moment': 'libs/moment/moment.min',
                'ojdnd': 'libs/dnd-polyfill/dnd-polyfill-1.0.0.min',
                'customElements': 'libs/webcomponents/CustomElements'

              },
       waitSeconds: 0,
       // urlArgs will be appended at end of .js files 
       urlArgs: "v=1.33",
      // Shim configurations for modules that do not expose AMD
      shim: {
          'jquery': {
           exports: ['jQuery', '$']
           }
          },
     config: {
              ojL10n: {
              merge: {
              //'ojtranslations/nls/ojtranslations': 'resources/nls/menu'
                 }
               }
             }
    });

您可以在每次部署新代码时更新版本(通过更改配置中的 urlArgs 参数),因此每次都会下载新的 JavaScript 文件。

于 2017-08-07T14:57:07.783 回答
0

这在开发过程中始终是一个问题。有几个解决方案。1) 构建到您的应用 URL 中,一个版本字符串。每次发布新版本时,更改该编号,浏览器将提取新文件 2) 在服务器上设置缓存控制值,使其不会缓存应用目录中的任何内容 3) 做你正在做的事情清除浏览器缓存。有一些实用程序可以在浏览器栏上添加一个按钮,以使其更容易访问。

我个人使用节点 http-server 库来运行我的开发工作,并使用它的缓存控制参数来确保没有缓存任何内容。

http-服务器 -c-1 -o

以上关闭缓存并从当前位置启动浏览器(加载 index.html 如果存在)

于 2017-06-09T16:16:52.107 回答
0

使用 Chrome:如果您打开开发者工具 ( F12),Network您可以在选项卡上选中Disable cache复选框,这会在 DevTools 打开时关闭缓存。

使用 Firefox:如果您打开开发者工具 ( F12),单击齿轮图标(“工具箱选项”),然后在“高级设置”部分中,选中Disable Cache (when toolbox is open)复选框。

现在浏览器中将没有缓存。可能会严重减慢速度...

于 2017-07-26T16:44:48.977 回答