Skip to content
This repository was archived by the owner on Sep 3, 2026. It is now read-only.
This repository was archived by the owner on Sep 3, 2026. It is now read-only.

Add a note about gzip being incompatible with HMR #10

Closed

Description

@STRML

If webpack-hot-middleware is installed after gzip middleware (like compression), no events will be sent as the buffers are not properly flushed.

This took a while to track down so it would be great if it were documented.

Alternatively, we can check for the existence of a res.flush() method and call it. This would make SSE work even if gzip is used. See expressjs/compression#17

Activity

  1. glenjamin commented on Sep 8, 2015

    @glenjamin
    Contributor

    Hrm, this is annoying. I can add in some notes to say that SSE is involved.

    I'm not massively keen on implementing a non standard stream method. Does the gzip middleware return true/false to indicate buffering status on write()? Could pump extra bytes in until it indicates it was completed - or maybe get it to treat write("") as a flush?

  2. glenjamin commented on Sep 8, 2015

    @glenjamin
    Contributor
  3. STRML commented on Sep 8, 2015

    @STRML
    Author

    I'm looking for a way to trick the compressor although I doubt there is a foolproof way.

    There's nothing wrong with compressing text/event-stream, except that you need to manually flush after each write.

    I agree that flush seems like a hack but I'm not sure if there is a better choice or that it would be any less robust than munging headers to trick compression.

  4. glenjamin commented on Sep 8, 2015

    @glenjamin
    Contributor

    Perhaps @dougwilson could weigh in? How best to not break upstream buffering plugins without specifically coding for compression?

  5. dougwilson commented on Sep 8, 2015

    @dougwilson

    All we do is pump to the built-in zlib.createGzip in Node.js. Their stream is what requires the .flush() calls, which is why we expose it on res. I don't think there's any way around it. We also do properly return true/false on writes (it's just whatever value the .write() on the Node.js gzip stream returned).

  6. dougwilson commented on Sep 8, 2015

    @dougwilson

    One possibility is that we could, perhaps, change the default response filter to look for a Cache-Control response header, and not compress if the declaration no-transform is in there, which could be a good general way you could opt-out of compression without requiring users to do a bunch of configuration and that, as a generic default, makes sense to me. Thoughts?

  7. STRML commented on Sep 8, 2015

    @STRML
    Author

    That seems good to me and fits the semantics of no-transform.

  8. dougwilson commented on Sep 8, 2015

    @dougwilson

    Cool. Tracking issue: expressjs/compression#51

  9. glenjamin commented on Sep 8, 2015

    @glenjamin
    Contributor

    I can pick up doing a PR on both sides of no-one else beats me to it

  10. marcello3d commented on Sep 15, 2015

    @marcello3d

    Also spent a couple hours tracking down this bug (twice, in fact, several weeks apart). :-)

  11. glenjamin commented on Sep 19, 2015

    @glenjamin
    Contributor

    Added a troubleshooting note in 129de82, the new header is included in v2.0.2, but still waiting on the upstream PR to be merged into compression.

    Will leave this bug open until that's merged too.

  12. dougwilson commented on Sep 30, 2015

    @dougwilson

    Published to npm as [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions