Giter VIP home page Giter VIP logo

Comments (29)

PatrickJS avatar PatrickJS commented on April 27, 2024 7

+1

from http-server.

smarts avatar smarts commented on April 27, 2024 4

I got this working locally (as an always-on feature, not configurable) by modifying http-server.js:

  before.push(ecstatic({
    gzip: true, // HACK: I ADDED THIS LINE!
    root: this.root,
    cache: this.cache,
    showDir: this.showDir,
    autoIndex: this.autoIndex,
    defaultExt: this.ext,
    handleError: typeof options.proxy !== 'string'
  }));

ecstatic will check if the accept-encoding header allows compression, and if present will look for a file that matches the requested file name with '.gz' at the end. For example:
this request: http://example.com/foo.css
with this header: Accept-Encoding: gzip, deflate, sdch
will look for a file called foo.css.gz and will serve it w/ the Content-Encoding: gzip HTTP header if it exists

from http-server.

derhuerst avatar derhuerst commented on April 27, 2024 4

Please use the reaction feature to express you'd like to have this feature.

from http-server.

BigBlueHat avatar BigBlueHat commented on April 27, 2024 2

@smarts it's been an option since 0.10.0 was released https://github.com/indexzero/http-server/releases/tag/0.10.0 😄 If you need something more, perhaps open a new issue so we can discuss that there rather than on this closed issue.

from http-server.

mydearxym avatar mydearxym commented on April 27, 2024 1

+10

from http-server.

derhuerst avatar derhuerst commented on April 27, 2024 1

Is this feature available in the npm package yet?

Nope. npm info http-server gitHead says the published git commit is 1a8552c5e028bd5500027ee940111133927a4e94. 1a8552c is behind b456b77, which added gzip support.

from http-server.

golopot avatar golopot commented on April 27, 2024 1

For what I understand the current --gzip option requires you to produce something.ext.gz by yourself. But what I want is a option that does the compression on the fly, like the express middleware app.use(compression()), just plug in one line and no hassle.

from http-server.

Nashorn avatar Nashorn commented on April 27, 2024 1

Seriously, don't understand how hard on-the-fly compression can be, in just a few lines:

var zlib = require('zlib');

pathName = url.parse(request.url).pathname;
var fp = __dirname+"/../.."+pathName; //custom patthing, ignore

var readStream = fs.createReadStream(fp);
readStream.on('open', function (res) {
response.writeHead(200, { 'content-encoding': 'gzip' });
readStream.pipe(zlib.createGzip()).pipe(response);
});

from http-server.

gr0uch avatar gr0uch commented on April 27, 2024

+1

from http-server.

chadxz avatar chadxz commented on April 27, 2024

+1 would like this too

from http-server.

hungsu avatar hungsu commented on April 27, 2024

+1 This sure would be sweet!

from http-server.

KyleAMathews avatar KyleAMathews commented on April 27, 2024

+1

from http-server.

mathiasschopmans avatar mathiasschopmans commented on April 27, 2024

👍

from http-server.

LukeAskew avatar LukeAskew commented on April 27, 2024

+1

from http-server.

Tims101 avatar Tims101 commented on April 27, 2024

👍

from http-server.

michael-lawrence avatar michael-lawrence commented on April 27, 2024

👍

from http-server.

axwell avatar axwell commented on April 27, 2024

No news on this ?

from http-server.

avesus avatar avesus commented on April 27, 2024

👍

from http-server.

hanai avatar hanai commented on April 27, 2024

It't really useful.

from http-server.

tomkel avatar tomkel commented on April 27, 2024

+1!

from http-server.

mattlavallee avatar mattlavallee commented on April 27, 2024

doing an npm install of http-server doesn't seem to pull in the gzip property event after an npm cache clean. Is this feature available in the npm package yet?

from http-server.

BigBlueHat avatar BigBlueHat commented on April 27, 2024

@golopot right now, I'd say that on-the-fly compression is "out of scope" for a static web server--which should really just transmit content with minimal involvement. If you'd still like to discuss it, though, please file a separate issue. Thanks!

from http-server.

WickyNilliams avatar WickyNilliams commented on April 27, 2024

To be clear, on-the-fly compression was exactly what I wanted when i originally opened this issue

from http-server.

BigBlueHat avatar BigBlueHat commented on April 27, 2024

Good to know @WickyNilliams. At this point, I don't plan on going beyond what's "underneath" in the form of node-ecstatic's support https://github.com/jfhbrook/node-ecstatic#optsgzip

There are few things we're adding here, but mostly I'm wanting to continue to build up from the node-ecstatic foundation. Any sort of server-side content processing would be out-of-scope in that case.

from http-server.

smarts avatar smarts commented on April 27, 2024

@BigBlueHat i wasn't necessarily looking for on-the-fly compression. As noted in my previous comment
#56 (comment)
i got it working w/ a hack, but i'd like this to be supported by the server's options instead of having to hack it myself. Can it be added as an option?

from http-server.

smarts avatar smarts commented on April 27, 2024

Doh! I now see the pull request that references this issue. Thanks for being patient w/ me @BigBlueHat 😅

from http-server.

Viyozc avatar Viyozc commented on April 27, 2024

+100

from http-server.

thornjad avatar thornjad commented on April 27, 2024

@Nashorn you're more than welcome to turn your suggestion into a pull request!

from http-server.

Nashorn avatar Nashorn commented on April 27, 2024

It's not clear from looking at http-server.js, where I would integrate the above solution which does dynamic gzip compression on responses. I found this area, but not even sure where/how to plug in.

var serverOptions = {
    before: before,
    headers: this.headers,
    onError: function (err, req, res) {
      if (options.logFn) {
        options.logFn(req, res, err);
      }

      res.end();
    }
  };

from http-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.