31

I am trying to determine what the difference is between the Transferred column and Size column. Does it have to do with the difference between compressed files and uncompressed?

I am not compressing my files on my server (Node.js Express server) so I don't know why there would be a difference in file size.

enter image description here

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
  • 1
    for chrome http://stackoverflow.com/questions/8072921/chrome-dev-tools-size-vs-content. But you'll get the idea. – hassansin Aug 14 '15 at 01:30

1 Answers1

30

Your express application has gzip compression enabled as indicated by the Content-Encoding: gzip header, so the response body is compressed with gzip before sending over the network. Transferred size is when compressed, and size is decompressed in the browser. Express is doing this on the fly, so even though your file is not compressed on disk, it gets compressed before it is sent over the network.

Follow-up on your comments

You haven't posted any code, but it's probable that your express application is using the compression middleware (perhaps from the boilerplate you started with). If so, that will use mime-db to determine if the response content type is compressible. Looking up application/javascript in mime-db reveals it is marked as compressible:

mimeDb['application/javascript']
{ source: 'iana',
  charset: 'UTF-8',
  compressible: true,
  extensions: [ 'js' ] }

Note that a .gz file extension is not involved anywhere here. There is no .gz file on disk, the compression is being done to a .js file in memory. Also note that just setting the Content-Encoding: gzip header without actually encoding the body as gzip is not something you want to do. It will cause encoding errors for the client.

Peter Lyons
  • 142,938
  • 30
  • 279
  • 274
  • 1
    huh, you're right, it looks like Express is doing the gzip-ing out of the box. I didn't know it gzipped .js assets out of the box. I thought I added that myself, using app.get('*.gz', function(req,res,next){ res.set('content-encoding','gzip')}); – Alexander Mills Aug 14 '15 at 05:53
  • it's possible that the regex '*.gz' is capturing .js files, since I am not that familiar with Express regex's – Alexander Mills Aug 14 '15 at 06:02