How can append query string to chunk files request when I use require.ensure ?

I have use require.ensure to generator async chunk files like:

require.ensure([],function(require){
  let Page1 = require('./page-1');
  let Page2 = require('./page-2');
//...
},'page-chunk')

When I want to refresh the broswer cache after I changed code and rebuild, I use chunkhash at config file and make chunks have a new flie name:

output: {
  //...
  chunkFilename: outputDir + "/[id].[name]-[chunkhash].js"
},

But it has ouccr too many files over and over again. and I often need to delete old files both local and server(also maybe it is unsafe):

Too many generator files

QUESTION: Is there any way I can use query string for chunk files? I mean, for example :

require.ensure([],function(require){
  let Page1 = require('./page-1');
  let Page2 = require('./page-2');
//...
},'page-chunk', '?ver=[chunkhash]')

Then request should append search string when fetch the script like it:

http://cdn.com/path/output/1.page-chunk.js?ver=c5434xxxxxxx

Anyone have any experience on this? Thanks and looking forward to your help. 😦

Author: Fantashit

2 thoughts on “How can append query string to chunk files request when I use require.ensure ?

    • User opens app with hash 1234.
    • User loads app.js?1234 and chunk1.js?1234
    • User leaves the app open
    • You publish an update with hash 5678
    • User requests another chunk: chunk2.js?1234
    • App crashes because chunk2.js?1234 (loaded after the update) isn’t consistent with app.js?1234 (loaded before the update), because chunk2.js was overwritten by your update and is now chunk2.js?5678.

Comments are closed.