How to do gzip most efficiently in express react app made using nextjs framework and hosted on heroku
It should be possible to enable gzip compression using a custom nginx buildpack in front of your NextJS app.
$ heroku buildpacks:add heroku-community/nginx
Add the build pack and create a file config/nginx.config.erb
with a config like this:
http { gzip on; gzip_comp_level 2; gzip_min_length 512; server { listen <%= ENV["PORT"] %>; server_name _; keepalive_timeout 5; location / { <% if ENV['NGINX_SKIP_HTTPS_PROXY'] == 'true' %> if ($http_x_forwarded_proto != "https") { return 301 https://$host$request_uri; } <% end %> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://localhost:3000; #next serve listens here and receives nginx requests } }}
You can find the full configuration details in this post.