转载自: http://inspiredjw.com/do-not-forget-to-use-gzip-for-express/
When a gzip compatible browser requests to a web server, web server can compress the response to the browser back and the browser can decompress the response and finally the browser get the original response.
If the server does not take care of gzip compression, the original size of data is passed which takes longer time than using gzip because it is sending bigger data!
For Express 2.x, I used to use Gzippo which is no longer working for recent version of Node.js and Express.
Since Express 3.x, the express.compress()
is available with Express itself.
How to apply Gzip?
In your main file something like app.js
or index.js
, you have bunch of app.use
.
app.use(express.json());
app.use(express.urlencoded());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
Add express.compress()
at the very top would enable the gzip compression on your web server.
app.use(express.compress());
app.use(express.json());
app.use(express.urlencoded());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
For Express 4.x
You need to install middlewares separately for Express 4.x.
var compress = require('compression');
app.use(compress());
Check your website
After applying gzip on your web server, you should check your website whether it is using gzip or not.
Go to GzipTest and enter your site url.
If you see this, you are successfully applied gzip compression on your website!
相关推荐
To get the most out of this book, you'll need to know the basics of web application design and be proficient with JavaScript. About the Author Evan Hahn is an active member of the Node and Express ...
Designed for use by novice computer users, this text begins with the basics, such as starting SPSS, defining variables, and entering and saving data. All major statistical techniques covered in ...
but Vue.js makes this daunting task simple and easy to learn, allowing you to start implementing business needs with just a script reference to the library and the custom JavaScript required for your ...
Shader Forget 1.32版本, 支持Unity5.x的使用, 亲测可用
I explain new and interesting bits of syntax, but this book isn’t primarily about teaching you how to use JavaScript. It’s about teaching you how to build real applications by using AdonisJs. The ...
You will begin with a basic RESTful web service in Node.js, using the popular Express.js framework, pre-built and ready to run in your local environment. You will be introduced to the most powerful ...
Learn to use Node.js by creating a fully functional social network About This Book Plan and implement a modern Node.js application Get to know the most useful Node.js capabilities Learn how to create...
Explore Vue.js to take advantage of the capabilities of modern browsers and devices using the fastest-growing framework for building dynamic JavaScript applications. You will work with the power of ...
You will learn, for example, how different traditional design patterns look in Node.js, or how to design modules that do only one thing. A set of patterns to solve common Node.js design and coding ...
The Backbone.js library can be difficult to master, but in this book you will get the necessary skill set to create applications with it, and you will be able to use any other library you want in your...
but Vue.js makes this daunting task simple and easy to learn, allowing you to start implementing business needs with just a script reference to the library and the custom JavaScript required for your ...
(IDE) that you can use for developing COBOL programs on your own PC. To help you get the most from this IDE, this document provides exercises that are carefully coordinated with the first 16 chapters ...
主要讲解了express 的get请求
Express.js is a web application framework for Node that organizes server-side JavaScript into testable, maintainable modules. It provides a powerful set of features to efficiently manage routes, ...
Beginning Node.js is great for front-end developers looking to use Node.js in their websites. If you understand the basics of programming this book will teach you how you can leverage JavaScript to ...
but Vue.js makes this daunting task simple and easy to learn, allowing you to start implementing business needs with just a script reference to the library and the custom JavaScript required for your ...
Thus it is a bit difficult for the student to focus on what are the essential parts of this subject. What must one absolutely know for the qualifying exam? What will be asked? What techniques will be ...
Do you want to build web pages but have no prior experience? This friendly guide is the perfect place to start. You’ll begin at square one, learning how the web and web pages work, and then steadily ...
This guide contains step-by-step examples to get you started test driving in C, especially for embedded software applications. We'll look at how to use the unit test framework called Ceedling to help...