首页 > 其他分享 >Do not forget to use Gzip for Express.js

Do not forget to use Gzip for Express.js

时间:2023-05-21 14:04:47浏览次数:48  
标签:Do use Express forget app express gzip your


 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()

 

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()

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 :)

标签:Do,use,Express,forget,app,express,gzip,your
From: https://blog.51cto.com/u_2700990/6319192

相关文章

  • Windows 2012安装mysql 5.7.21
    文档课题:Windows2012安装mysql5.7.21系统:MicrosoftWindowsServer2012Standard64位数据库:mysql5.7.21安装包:mysql-installer-community-5.7.21.0.msi1、下载自MySQL版本升级到5.7后,安装和配置过程发生很大变化,以下介绍5.7版本MySQL的下载、安装及配置过程.针对不同......
  • python基础-进程池、submit同异步调用、shutdown参数、ProcessPoolExecutor进程池、进
    转载:(14条消息)python基础-进程池、submit同异步调用、shutdown参数、ProcessPoolExecutor进程池、进程池ftp_pythonsubmit_易辰_的博客-CSDN博客引入进程池在学习线程池之前,我们先看一个例子frommultiprocessingimportProcessimporttimedeftask(name):print(......
  • 微软推出Windows 11 Insider预览版22621.1255和22623.1255
    您好,WindowsInsider,今天我们将向Beta频道发布Windows11Insider预览版22621.1255和22623.1255(KB5022918)。Build22623.1255=推送新功能。Build22621.1255=默认情况下关闭新功能。提醒:以前在22622版本上的内部人员将通过启用包自动转移到22623版本。启用包人为地增加了新功能推出......
  • 欢迎使用CSDN-markdown编辑器
    欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗Ctrl+B斜体Ctrl+I......
  • mongodb基本概念 && docker安装
    https://blog.csdn.net/packge/article/details/1265393201mongoDb采用内存加磁盘的方式存储数据;2mongoDb支持数据分片,当单一的服务器中磁盘不够用的时候,还可以串联其他服务器;3客户端的请求到达内存时,先在日志中记录下操作记录,然后再去操作内存;4内存中的日志每10ms向磁盘中的......
  • Field userClient in com.demo.order.service.OrderService required a bean of type'
    在SpringCloud项目中使用Feign进行远程调用遇到的错误。原因是因为UserClient在com.demo.feign.clients包下面,而order-service的@EnableFeignClientd注解却在com.demo.order包下面,这两个不在同一个包下,无法扫描到UserClient。解决方法有两种1.指定Feign应该扫描的包@EnableFeig......
  • Windows平台下安装binwalk
    (4条消息)Windows平台下安装binwalk_binwalk下载_烟雨天青色的博客-CSDN博客https://blog.csdn.net/qq_38603541/article/details/126557575关于binwalkBinwalk是一款快速、易用,用于分析,逆向工程和提取固件映像的工具。简单易用,完全自动化脚本,并通过自定义签名,提取规则和插件模......
  • Python虚拟环境,多版本共存-windows安装【记录】
    使用virtualenv可以快速创建干净的环境,并且可以指定版本。安装virtualenvpipinstallvirtualenv创建虚拟环境virtualenv-pD:\Python\Python36\python.exevenv36D:\Python\Python36\python.exe可以选择已安装的python版本venv36创建的虚拟环境的目录进入虚拟环境......
  • Dockfile练习一:给ubuntu1804设置Java环境
    [root@mondoopt]#catDockerfile#BaseimageFROMubuntu:18.04#MAINTAINERMAINTAINERzhangjq<[email protected]># 将宿主机的软件包,复制到容器里的/usr/local/src目录下面去ADDjdk-8u321-linux-x64.tar.gz/usr/local/src/# 将上面的容器软件包进行解压,解压到jdk1.8.......
  • 用Docker发布Study.BlazorOne.Blazor到公网测试服务器
    #1、准备公网上的测试数据库。之前我们在VisualStudio里面调试的时候,使用的都是localhost的数据库。现在需要在公网上准备一个SQLServer。然后执行下面的步骤1)把Study.BlazorOne.DbMigrator设置为启动项目;2)修改appsettings.json中的连接字符串将本地localhost的配置注释掉,加上......