Gzip Netlify function response

How can I gzip Netlify function reponse? It’s quite big 2MB JSON.

Hi, you’ll need to gzip your response within your function directly. Something like:

const zlib = require('zlib');

const helloWorld = "<html><head><title>Gzipped hello world!</title></head><body><h1>Gzipped hello world!</h1></body></html>";

exports.handler = (event, context, callback) => {
    zlib.gzip(helloWorld, (error, gzippedHelloWorld) => {
        if(error) console.log(error);
        const response = {
            statusCode: 200,
            body: gzippedHelloWorld.toString('base64'),
            isBase64Encoded: true,
            headers: {
                'Content-Type': 'text/html',
                'Content-Encoding': 'gzip'
        callback(null, response);

Let me know if that works for you.