2

我正在使用 yeoman + grunt + angularJs 开发应用程序。

为了仅在需要时加载 JS 文件,我在 calendar.html 中添加了 JS 文件路径。

为此,我修改了 grunt.js 和 html 文件。

Grunt.JS 文件

useminPrepare: {
        html: ['<%= yeoman.app %>/index.html', '<%= yeoman.app %>/views/*.html'],
        options: {
            dest: '<%= yeoman.dist %>',
            flow: {
                html: {
                    steps: {
                        js: ['concat', 'uglifyjs'],
                        css: ['cssmin']
                    },
                    post: {}
                }
            }
        }
    }

修改 calendar.html 文件

<!-- build:js({.tmp,app}) scripts/fullcalendar.js -->
  <script src="scripts/plugins/fullcalendar/fullcalendar.js"></script>
<!-- endbuild -->

此解决方案工作正常。但是现在每当我加载我的日历页面时,都会向 fullcalenar.js 发出一个新的请求,其中包含像这样的动态查询字符串参数

http://localhost/scripts/fullcalendar.a13f9b72f8.js?_=1422010995753

每次我发出阻止浏览器缓存文件的请求时,这个数字 (1422010995753) 都会增加。

我相信这是因为assetCacheBuster,但这是我对Grunt的配置。我已经将它与 debugInfo 一起设置为 false。

   compass: {
        options: {
            javascriptsDir: '<%= yeoman.app %>/scripts',
            fontsDir: '<%= yeoman.app %>/styles/fonts',
            importPath: './bower_components',
            relativeAssets: false,
            assetCacheBuster: false,
            raw: 'Sass::Script::Number.precision = 10\n'
        },
        server: {
            options: {
                debugInfo: false
            }
        }
    }

我的问题是,我想缓存 fullcalendar.js 文件,不想每次都获取新的 JS 文件。

如果我在 index.html 文件中的 calendar.html 代码上方移动,则应用程序可以正常工作并缓存文件而不与其余的 js 结合。但是,如果我在 index.html 中添加该代码,fullcalendar.js 文件将与第一页一起加载。

4

1 回答 1

0

迟到的答案:grunt-cachebuster-querystring

于 2016-04-12T13:16:47.357 回答