【问题标题】:CacheBusting using grunt not updating referencesCacheBusting 使用 grunt 不更新引用
【发布时间】:2020-07-22 00:40:53
【问题描述】:

我正在使用 npm grunt-cache-bust 来缓存静态文件。

我有以下文件夹结构

- app
    - scripts
         - app.js
         - app.config.js
         - controllers
             - controller1.js
             - controller12.js
    - index.html
- Gruntfile.js

在 gruntfile.js 我添加了基本配置

    cacheBust: {
      taskName: {
          options: {
              assets: ['dist/scripts/**'],
              jsonOutput: true,
              createCopies: true,
              deleteOriginals: false    
          },
          src: ['dist/index.html',]
      }
    }

它破坏了 src 中给出的文件,但不替换 index.html 中的引用

我有什么遗漏吗?

【问题讨论】:

    标签: angular caching npm gruntjs browser-cache


    【解决方案1】:

    我遇到了类似的问题,这是因为我在 index.html 中的导入路径没有dist/scripts/** 的形式,而是scripts/**。我解决了这个问题,方法是为我要销毁的文件指定 baseDir,为需要更新其引用的文件指定 cwd:

        cacheBust: {
            taskName: {
                options:{
                    baseDir:'<%= somedir %>/',
                    assets:['**.js'],
                    deleteOriginals: true
                },
                files: [{
                    expand: true,
                    cwd: '<%= somedir %>/',
                    src: ['index.html']
                }]
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-02
      • 2017-09-14
      • 2014-10-16
      • 1970-01-01
      • 2013-09-19
      • 2013-12-02
      相关资源
      最近更新 更多