0

I want to combine two gzipped files: dist/public/scripts/vendors.js.gz and dist/public/scripts/scripts.js.gz. I am currently trying to do it like this:

gulp.task('scriptCombination', ['compressScripts'], () => {
    var jsDest = 'dist/public/scripts';
    gulp.src(['dist/public/scripts/vendors.js.gz', 'dist/public/scripts/scripts.js.gz'], { base: '.' })
    .pipe(concat('new-file.js.gz'))
    .pipe(gulp.dest(jsDest));
});

Right now it seems like the first file is zipping correctly, but the second file always seems to get messed up. Upon return and unzip, the files will look good at first, but scrolling down it seems like things get really messy. new-file.js.gz ends up looking something like this when it is unzipped in the browser:

oadprogress","reset","queuecomplete"];e.forEach(p,function(o){var n=t.callbacks[o]||e.noop;s.on(o,function(){n.apply(null,arguments),t.$$phase||t.$root.$$phase||t.$apply()})})}}}}])}"object"==typeof module&&module.exports?module.exports=o(require("angular"),require("dropzone")):"function"==typeof define&&define.amd?define(["angular","dropzone"],o):o(e.angular,e.Dropzone)}(this);
‹�����í=ksÛ¶–ß÷W0œ\/¹Ah;¶¡ÂzœWë½Mš‰tîf²Z„-Æ©’”EÖ߃'¤(ÇN;s7Ó©…×p^À9�Oçù¸N‹ÜyìÃü¦xž¥ãsÏ_žŠ¢,ÍϽj\Ì0žâ¼Fq]—éɼÆ×eæ//âÒIó‰H:8ÃõQ|ò’Õ> ùoê(¤àîe\'^(˜ŠŒ‘èÚ‹iŽ¿d·¶<
ý´Ï«ƒ¦·

(good and minified for the first file, bad for the second)

How can I combine these two files in gulp?

Luke Schlangen
  • 3,722
  • 4
  • 34
  • 69
  • unzip them, concat, then zip again. Or simply concat them before zipping, in the first place – Thomas May 07 '17 at 07:20
  • Thanks Thomas. I can't do that in this case because to recompress everything takes longer than what heroku allows in build time. Is there another way to do it without unzipping? – Luke Schlangen May 07 '17 at 07:48
  • After googling a bit, technically it should be possible to simply concat multiple `gz` files into a single one; there are even [examples doing exactly that](http://stackoverflow.com/questions/8005114/fast-concatenation-of-multiple-gzip-files). I guess there might be a bug in your decompressor? Maybe related to the file header in the successive file. Or maybe `concat()` injects something between the files to seperate them? I can't help you here; I cannot debug this from the distance. But again, how about concatenating these files before compressing them in the first place? – Thomas May 07 '17 at 10:15
  • A quick test with a few recent browsers shows that they don't support multiple gzipped blocks in a single response: Chrome 58 will gunzip the first one, but not the second one (it's shown as the gzipped data), and Safari and Firefox will only decompress and show the first block. – robertklep May 07 '17 at 11:07
  • Bummer. Unfortunately, I can't gzip them together right away, so that one isn't an option. Thanks for the help! – Luke Schlangen May 07 '17 at 14:58

0 Answers0