expressjs / serve-static

Serve static files
MIT License
1.38k stars 227 forks source link

Support gzip static serving #134

Closed licg9999 closed 4 years ago

licg9999 commented 4 years ago

https://github.com/expressjs/serve-static/issues/133

dougwilson commented 4 years ago

Thank you. Though this is appreciated, it is a feature that is not desired in this package (see previous issues regarding this). You are always welcome to publish this to npm as a fork if you desire, as the code is MIT licensed.

licg9999 commented 4 years ago

Hi, I think expressjs/compression is good for dynamic api serving but not good for static gzip file serving because it make compression on every response, which means a lot of cpu usage. In fact, Pre-compression file serving is a very basic feature for a static file server, you may have a look at ngx_http_gzip_static_module and found it simple but useful.

dougwilson commented 4 years ago

Unfortunately all static file serving is not good to be done by Node.js, as Node.js does all file I/O on a thread pool, which has only limited threads and CPU usage. You should always use a proper file server like NGINX, Apache, or a CDN with Node.js as the origin server if at all possible.

licg9999 commented 4 years ago

If all static file serving should be done by NGINX / Apache, then why should expressjs/serve-static be there? In some simple situation or non-production environment, expressjs/serve-static is a good option, but now I have to setup another file server to go on. It's not proper for me at all.

dougwilson commented 4 years ago

You've already written the code and there is nothing that would keep you from publishing your code to npm for your use or anyone else; not accepting it here is not preventing you from using what you like :) Just publish your module, make use of it.

dougwilson commented 4 years ago

In fact, here is an already published module that should meet your needs, and looks like it has some more features that you could make use of: https://www.npmjs.com/package/express-static-gzip

licg9999 commented 4 years ago

Functionally, it's ok...

In my opinion, pre-compression file serving should be considered to be a part of a static server.

Though express-static-gzip is built upon serve-static, but its implementation is redundant. express-static-gzip has done several same logic as serve-static to extend functionality, and it's not eligant.

If you insist not to integrate pre-compression file serving, would you expose some mechanism to extend serve-static itself?

dougwilson commented 4 years ago

If you think that module can be improved, please open a PR or issue to it, just like you did here.