Closed licg9999 closed 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.
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.
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.
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.
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.
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
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?
If you think that module can be improved, please open a PR or issue to it, just like you did here.
https://github.com/expressjs/serve-static/issues/133