Next.js: Any Gzip tips for Next 2.0 ?

Created on 27 Apr 2017  路  4Comments  路  Source: vercel/next.js

Hi,

I saw some issues on Gzip compression here, but I can't find a clear solution for this. I'm using Next 2.0 and the site is hosted by Heroku. What do I have to do to get the GZip compression please ?When I test my site on gtmetrix or gidnetwork, I can see the Gzip compression is not enable...

Thanks a lot for helping

Most helpful comment

I used the following in my express config:

const compression = require('compression');
const express = require('express');

...

const server = express();
server.use(compression());

...

Your need of course to install the compression package, npm install compression --save

hope this helps

All 4 comments

I used the following in my express config:

const compression = require('compression');
const express = require('express');

...

const server = express();
server.use(compression());

...

Your need of course to install the compression package, npm install compression --save

hope this helps

Thanks @stefano-DM for helping.
@guillaumeko you can do it as like above or using a proxy infront of your app like nginx or even Cloudflare.

Thanks guys !!!

I just put my complete server.js in case someone have the same question:

`
const express = require('express')
const compression = require('compression')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare()
.then(() => {
const server = express()
server.use(compression())

server.get('/page1', (req, res) => {
return app.render(req, res, '/resume', req.query)
})

server.listen(process.env.PORT || 3000, (err) => {
if (err) throw err
console.log('> Ready on http://localhost:3000')
})
})
`

Thnaks

Was this page helpful?
0 / 5 - 0 ratings