0

I am using lite-server locally for angular2 dev. I compressed all my js into a min.js file with 1.7Mb which is working fine. Now I want to squeeze it to a gzip file with 280Kb which is much smaller. The bad part is that Chrome is downloading the file with content-type "octet-stream" instead of "application/javascript" and the Content-Encoding "gzip". Is there any simple way of making this work?

pedrotorres
  • 1,222
  • 2
  • 13
  • 26
  • Look at what headers your server is sending. You can see these in the chrome inspector in the network panel under the resource in question. – Dan D. Jul 04 '16 at 10:37
  • as i said: it's sending the file as 'octet-stream' and thats my problem. Here's the headers: Accept-Ranges:bytes Cache-Control:public, max-age=0 Connection:keep-alive Content-Length:295997 Content-Type:application/octet-stream Date:Mon, 04 Jul 2016 09:58:44 GMT ETag:W/"4843d-155a79e0518" Last-Modified:Fri, 01 Jul 2016 17:59:59 GMT – pedrotorres Jul 04 '16 at 10:39

1 Answers1

1

Not very familiar with lite-server, but since it seems to accept Express middleware you should be able to use the compression middleware:

// lite-server-config.js
module.exports = {
  ...
  server : {
    middleware : { 1 : require('compression')() }
    ...
  }
};

That will take care of the compression for you, so you don't have to gzip the files manually. It will also set the correct headers.

robertklep
  • 198,204
  • 35
  • 394
  • 381
  • thanks your answer oriented me to fix this problem with this answer: https://github.com/BrowserSync/recipes/tree/master/recipes/server.gzipped.assets – pedrotorres Jul 04 '16 at 11:20