Be the first user to complete this post

  • 0
Add to List

gzip compress and cache api response in express

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

Install the express and 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. [wpgist id="612ce6984de6e0f4ff95" file="gzip.js"]
Watch the following video to see the quick demo of css compression!
[youtube https://www.youtube.com/watch?v=ZqeZwluij7c]

Verify that your site is Gzip enabled or not : Verify the page speed for your site before and after the gzip enabled: References :



Also Read:

  1. Debugging nodejs applications using node-inspector and Chrome Dev Tools
  2. Installing, Listing and Uninstalling packages using npm
  3. Generators and Yield in es6
  4. Error: can not find module 'underscore'
  5. Resolved - Error: listen eaccess using nodejs and pm2