`
hongtoushizi
  • 浏览: 358403 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

Do not forget to use Gzip for Express.js

阅读更多

转载自: 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!

If you have some questions or want to say something about this post, you can comment below :)
分享到:
评论

相关推荐

    Express in Action: Writing, building, and testing Node.js applications

    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 ...

    How.to.Use.IBM.SPSS.Statistics.epub

    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 ...

    Getting to Know Vue.js

    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的使用

    Shader Forget 1.32版本, 支持Unity5.x的使用, 亲测可用

    The Definitive Guide to AdonisJs_Building Node.js App with JavaScript-2018

    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 ...

    Beginning.Amazon.Web.Services.with.Node.js.1484206541

    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 ...

    Node.js.By.Example.1784395714.epub

    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...

    Pro Vue.js 2(pdf英文原版-2018版)

    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 ...

    Node.js Design Patterns Second Edition[July 2016]

    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 ...

    Mastering.Backbone.js.1783288

    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...

    Getting to Know Vue js

    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 ...

    Net Express exercises.pdf

    (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 的get请求

    Express in Action(Manning,2016)

    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

    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 ...

    Getting to Know Vue.js Learn to Build Single Page

    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 ...

    A Guide to Complex Variables (Steven G. Krantz 2007).pdf

    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 ...

    Learning Web Design: A Beginner’s Guide to HTML... ..., 5th Edition

    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 ...

    How+to+Use+Ceedling+for+Embedded+Test-Driven+Development.pdf

    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...

Global site tag (gtag.js) - Google Analytics