Browsers are really good at understanding gzipped responses and this creates an opportunity for you to decrease the initial page load time and improve your website’s performance by gzipping all of your API responses. This is achieved by taking advantage of the content-encoding http header.
It’s particularly easy to do so using express. While at it, we will also see how to easily serve cached static content from your express server
- To serve and cache the static content using static middleware
- compress (gzip) all of your server responses using compress middleware
compression package as a dependency
npm i express --save npm i compression --save
Refer to the following gist for how to set it up in your app.
Verify that your site is Gzip enabled or not :
Verify the page speed for your site before and after the gzip enabled: