Suppose I have 2 separate gziped html chunks in memory. Can I send chunk1 + chunk2 to an HTTP client? Does any browser support this? Or is there no way to do this, and should I gzip the entire stream not in separate pieces?
I want to serve clients like chunk1 + chunk2 and chunk2 + chunk1 etc. (different order), but I donβt want to compress the whole page every time, and I donβt want to cache the whole page. I want to use pre-compressed cached chunks and send them.
nodejs code (node ββv0.10.7):
// creating pre cached data buffers var zlib = require('zlib'); var chunk1, chunk2; zlib.gzip(new Buffer('test1'), function(err, data){ chunk1 = data; }); zlib.gzip(new Buffer('test2'), function(err, data){ chunk2 = data; }); var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain', 'Content-Encoding': 'gzip'}); // writing two pre gziped buffers res.write(chunk1); // if I send only this one everything is OK res.write(chunk2); // if I send two chunks Chrome trying to download file res.end(); }).listen(8080);
When my sample server returns this response in the download window of the Chrome browser browser (it does not understand it: /
source share