压缩Node.js响应

时间:2016-07-13 05:44:14

标签: node.js express compression

我想在node.js服务器上压缩响应。因此,数据通过网络传输更快。

这有什么中间件吗?压缩我所有的服务器响应?

我正在使用express.js

1 个答案:

答案 0 :(得分:2)

我宁愿使用nginx来处理生产中的压缩。如果您仍想使用节点,请查看http://npmjs.com/package/compression

从自述文件中复制粘贴。

Started PUT "/users/password" for ::1 at 2016-07-13 17:14:44 +1000
Processing by Devise::PasswordsController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "user"=>{"reset_password_token"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Change my password"}
Can't verify CSRF token authenticity
  User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."reset_password_token" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["reset_password_token", "[FILTERED]"]]
   (0.0ms)  begin transaction
  Note Load (0.1ms)  SELECT "notes".* FROM "notes" WHERE "notes"."notable_id" = ? AND "notes"."notable_type" = ?  [["notable_id", 2], ["notable_type", "User"]]
  Organisation Load (0.1ms)  SELECT  "organisations".* FROM "organisations" WHERE "organisations"."id" = ? LIMIT 1  [["id", 1]]
  User Exists (0.1ms)  SELECT  1 AS one FROM "users" WHERE ("users"."login" = 'test1' AND "users"."id" != 2) LIMIT 1
   (0.0ms)  commit transaction
Redirected to http://localhost:3000/
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ?  ORDER BY "users"."id" ASC LIMIT 1  [["id", 2]]
Completed 302 Found in 44ms (ActiveRecord: 1.7ms)


Started GET "/" for ::1 at 2016-07-13 17:14:44 +1000
Processing by SessionsController#welcome as HTML
Completed 401 Unauthorized in 0ms (ActiveRecord: 0.0ms)


Started GET "/users/login" for ::1 at 2016-07-13 17:14:44 +1000
Processing by Devise::SessionsController#new as HTML
  Rendered users/shared/_links.html.erb (0.1ms)
  Rendered users/sessions/new.html.erb within layouts/application (2.2ms)
Completed 200 OK in 148ms (Views: 147.3ms | ActiveRecord: 0.0ms)