question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No HTML compression via custom server & app.render()

See original GitHub issue

Bug report

Describe the bug

If you write custom server routes via app.render() there is no gzip compression for the HTML document. I looked at the source code: the handleCompression() fn is only called via the app.getRequestHandler(). I guess this is not intended.

https://github.com/vercel/next.js/blob/8efc8be3e911e9c1eeabaef9e8cca6fcef5189ba/packages/next/next-server/server/next-server.ts#L866-L872

To Reproduce

  1. Clone the custom-server example (yarn create next-app --example custom-server custom-server-app)
  2. yarn build && yarn start
  3. Route to http://localhost:3000/a inspect HTML document response header via chrome dev tools or cURL
  4. There is no Content-Encoding: gzip response header 👎
  5. Route to index http://localhost:3000/ inspect HTML document response header via chrome dev tools or cURL
  6. Content-Encoding: gzip response header available 👍

Expected behavior

  • gzip compression of HTML documents rendered via app.render()
  • Response Header: Content-Encoding: gzip

System information

  • OS: macOS
  • Version of Next.js: 9.5.2
  • Version of Node.js: 12.18.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
radoslawgrochowskicommented, Mar 12, 2021

I’ve added test cases, @timneutkens.

I have one question - should app.render with /static content also be compressed?

1reaction
bobaaaaacommented, Sep 15, 2020

@YichiZ exactly

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to access next.js rendered HTML via custom server
The compression library is initialized using the handleCompression function of the Next.js's Server object (which is accessible using the ...
Read more >
Build a server-rendered React app with Next.js and Express
Next.js is a simple yet elegant approach to efficiently building server-rendered React apps with JavaScript. Get started with this tutorial.
Read more >
Advanced Features: Custom Server - Next.js
A custom Next.js server allows you to start a server 100% programmatically in order to use custom server patterns. Most of the time,...
Read more >
Static Sites | Render · Cloud Hosting for Developers
Deploy your static sites on Render in just a few clicks. Includes a global CDN, automatic TLS certificates, auto-deploys from Git, and custom...
Read more >
Express Tutorial Part 7: Deploying to production
That makes deployment quite easy because you just need to concentrate on your web application and not any other server infrastructure.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found