Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

gzipping should be done after minification #48

Closed
nirsharma opened this issue Oct 7, 2016 · 2 comments
Closed

gzipping should be done after minification #48

nirsharma opened this issue Oct 7, 2016 · 2 comments

Comments

@nirsharma
Copy link

in your readme, you've put
app.use(compression()); app.use(minify())

shouldn't this be other way around ?

@breezewish
Copy link
Owner

breezewish commented Oct 8, 2016

Yes gzip should be done after minification. However express-minify and compression rewrite function to "hook" the output of the response thus the order is reversed.

Let's say, a hook is as simple as:

var _send = res.send();
res.send = function (data) {
  // our own logic here
}

Then let's imagine multiple hooks (middleware A appears before middleware B):

var _sendA = res.send();
res.send = function (data) {
  // A
  manipulateA();
}

var _sendB = res.send();
res.send = function (data) {
  // B
  manipulateB();
}

Now when calling res.send, the order would be:

manipulateB
manipulateA

As you can see, hooks from later middlewares will be called first. That's how express-minify works.

In fact, minification cannot even work after gzip. The output from gzip is compressed binary data.

@nirsharma
Copy link
Author

I got it. thanks :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants