Re: [nodejs] HTTP - how to send multiple pre-cached gzipped chunks?

51 views
Skip to first unread message

Tim Caswell

unread,
May 24, 2013, 3:37:28 PM5/24/13
to nod...@googlegroups.com
gzip has internal headers that must only appear at the beginning.  You can't send two gzip documents in the same document.  The browsers don't support that.

If you have the same two chunks all the time, you can combine and then gzip once and send the one resulting chunk.


On Fri, May 24, 2013 at 2:04 PM, Sławek Janecki <jan...@gmail.com> wrote:

Lets say I have 2 individually gziped html chunks in memory. Can I send chunk1+chunk2 to HTTP client? Does any browser supports this? Or there is no way to do this and I have to gzip the whole stream not individual chunks?

I want to serve to clients for example chunk1+chunk2 and chunk2+chunk1 etc (different order) but I don't want to compress the whole page every time and I dont want to cache the whole page. I want to use precompressed 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 example server returns this kind of response Chrome browser display download window (it doesnt understand it :/

--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sławek Janecki

unread,
May 24, 2013, 3:42:40 PM5/24/13
to nod...@googlegroups.com
Is there any way to 'hack' it? For example striping gzpi headers from 2nd gzip chunk? Or that header is binded to gziped data?

Tim Caswell

unread,
May 24, 2013, 3:45:13 PM5/24/13
to nod...@googlegroups.com
I'm afraid I don't know gzip format well enough to answer that.  It's fairly well documented at http://www.gzip.org/zlib/rfc-gzip.html though.

Matt

unread,
May 24, 2013, 4:08:35 PM5/24/13
to nod...@googlegroups.com
In *theory* you might be able to do this by sending two multipart/mixed MIME sections, each having a Content-Encoding: gzip header. But I can't imagine that any browser would support it and display it properly.
Reply all
Reply to author
Forward
0 new messages