Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 265 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Express gzip static content

#1
Express and connect appeared to have removed their gzip functions because they were too inefficient. Are there any reliable solutions to gzip with express-js currently?
Reply

#2
If you've searched the npm you may have come across [node-compress][1].

It shouldn't be too hard to inject it as middleware into express.

[1]:

[To see links please register here]

Reply

#3
I have also searched npm and found for example:

-

[To see links please register here]


> gzippo pronounced g-zippo is a gzip
> middleware for Connect using Compress
> for better performance.

Gzippo has recently been developed(2 days ago) which I think is a good thing. I can't tell you about production usage. You should test/benchmark it yourself. I would also probably use a CDN for a live site or Nginx to host my static files instead of some nodejs module.
Reply

#4
Connect will support the new zlib stuff in Node in the next release
Reply

#5
[Connect 2.0][1] has added support for [compress()][2] middleware based on the [new zlib stuff][3] with that has just come out in Node Core API.

You can make use of this in your express server by adding a dependency to connect 2.0 in your `package.json` file:

{
...
dependencies: {
"connect" : "2.x",
"express" : "2.x",
// etc..
}
}

And then apply the following logic into your express app configuration:

// Create static file server with gzip support
var app = express.createServer(express.logger());
app.use(connect.compress());
app.use(express.static(__dirname + '/public'));
app.listen(80);

Please note that this stuff **is still pretty new** and while I could get it to work locally, my [Heroku][4] cloud application complained about the dependency on Compress 2.x during the pre-commit hook when deploying via git:

-----> Heroku receiving push
-----> Node.js app detected
-----> Resolving engine versions
Using Node.js version: 0.4.7
Using npm version: 1.0.106
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
npm ERR! Error: No compatible version found: connect@'>=2.0.0- <3.0.0-'

As you can see, they're still using an old version of node (0.4.7).

--------------
**UPDATE:**

Actually, I could get Heroku to deploy this by adding the corresponding `engines` section in the `package.json`:

{
...
"engines": {
"node": ">= 0.6.0 < 0.7.0"
}
}

And these are the results when using a http compression tester:


![enter image description here][5]

**UPDATE June 2014**

Hiya, if you are reading this now. Dont forget that the stuff above is only relevant to Express 2.0.

Express 3.0 and 4.0 use different syntax for enabling http compression, see post by gasolin just below.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

[5]:
Reply

#6
Express 3.0 now has compress() support:

var app = express();
// gzip
app.use(express.compress());
// static
app.use("/public", express.static(__dirname + '/public'));
// listen
app.listen(80);

**EDIT**
for Express 4.0, compress become the separate middleware. So you have to install and import to use it:

var compress = require('compression');
app.use(compress());
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through