Next.js: NextJS 9 - Compression?

Created on 21 Jul 2019  路  8Comments  路  Source: vercel/next.js

Question about Next.js

I'll preface this with i'm still learning NextJS i saw the changes in version 9 and realized that there's no reason not to convert now with typescript "first-class-citizen" support; so i just spent the last 45 hrs converting a smaller side project before converting some bigger projects at work just to see what problems i run into.

How do you get gzipping working on NextJS 9? i'm using the inbuilt server (pages/api) and therefore not using the custom server.

Lighthouse is telling me none of my assets are being gzipped therefore punishing me but there's no "end point" to attach the compression express middle-ware to for client JS.

TL;DR using new NextJS 9 inbuilt server but can't figure out of the life of me how to get asset compression working; putting it in custom server stops my /pages/api endpoints working.

Most helpful comment

FYI we're adding compression by default: https://github.com/zeit/next.js/pull/8066

All 8 comments

@ShanonJackson Did you find a solution? Could you post it here for folks googling the same question?

I have question related to this question too, since I wanted to use compression, I use custom server, and with this custom server, how to use the new api feature in next js 9, or if it cannot, then this issue is very important (also for caching too)

Hey @ShanonJackson!

Compression of assets is typically handled by a L7 proxy like nginx -- a next start server should have a proxy in front of it performing most of these duties (Gzip, caching, etc).
This setup will vary wildly based on your own infrastructure and hosting setup.

Deploying to ZEIT Now configures all of these things out of the box for you.
You can find instructions to deploy to Now here or here.

How to make all these middlewares work without custom server?
Has anyone workaround?

image

FYI we're adding compression by default: https://github.com/zeit/next.js/pull/8066

TL;DR compress outside of your application layer, nginx or your hosting provider should have that responsibility for those googling this.

@ShanonJackson i agree, now i use caddy server for compression and reverse proxy

Could you please post some information about how did you get caddy working with NextJS (Caddyfile)? Thx.

Was this page helpful?
0 / 5 - 0 ratings