# Compression Middleware

**URL:** <https://community.apollographql.com/t/compression-middleware/436>\
**Category:** Server\
**Tags:** server\
**Created:** [June 12, 2021, 8:28am UTC](https://community.apollographql.com/t/compression-middleware/436 "2021-06-12T08:28:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fawkesG5](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/fawkesg5/32/328_2.png) [@fawkesG5](https://community.apollographql.com/u/fawkesG5)\
**Post date:** [June 12, 2021, 8:28am UTC](https://community.apollographql.com/t/compression-middleware/436/1 "2021-06-12T08:28:16Z")

</div>

I am trying to use either compression or brotli compression using express middleware. I am using apollo-server-express integration.

The compression code is as follows:

```auto
app.use('/graphql',(req,res,next)=>{
        if(req.header('Accept-encoding').includes('br')){
            console.log('In here')
            app.use('/graphql',shrinkray({
                brotli:{
                    quality:9
                }
            }))
        }
        else{
            console.log('Out here')
            app.use(compression({
                level:7
            }))
        }
        next()
    })

```

Any help will be appreciated !!!

---

<div class="post-metadata">

**Author:** ![hwillson](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/hwillson/32/9_2.png) [@hwillson](https://community.apollographql.com/u/hwillson)\
**Post date:** [June 12, 2021, 10:51am UTC](https://community.apollographql.com/t/compression-middleware/436/2 "2021-06-12T10:51:55Z")

</div>

@fawkesG5 `apollo-server-express` uses `expressjs` behind the scenes, and last time I checked express doesn’t support brotli yet. Brotli support has tried to be added many times, and I think this PR has the best chance of succeeding, but it’s not there yet: [Added support for brotli ('br') content-encoding by danielgindi · Pull Request #172 · expressjs/compression · GitHub](https://github.com/expressjs/compression/pull/172)

As for using the `compression` middleware, it should work by following the Apollo Server [Applying middleware](https://www.apollographql.com/docs/apollo-server/integrations/middleware/#applying-middleware) docs.

---

<div class="post-metadata">

**Author:** ![fawkesG5](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/fawkesg5/32/328_2.png) [@fawkesG5](https://community.apollographql.com/u/fawkesG5)\
**Post date:** [June 12, 2021, 11:11am UTC](https://community.apollographql.com/t/compression-middleware/436/3 "2021-06-12T11:11:02Z")

</div>

But when I use a separate brotli middleware the webpage is compressed. And also I am using another package to enable brotli compression.

---

<div class="post-metadata">

**Author:** ![hwillson](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/hwillson/32/9_2.png) [@hwillson](https://community.apollographql.com/u/hwillson)\
**Post date:** [June 12, 2021, 1:49pm UTC](https://community.apollographql.com/t/compression-middleware/436/4 "2021-06-12T13:49:09Z")

</div>

Which Brotli middleware are you using?

---

<div class="post-metadata">

**Author:** ![fawkesG5](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/fawkesg5/32/328_2.png) [@fawkesG5](https://community.apollographql.com/u/fawkesG5)\
**Post date:** [June 14, 2021, 1:34pm UTC](https://community.apollographql.com/t/compression-middleware/436/5 "2021-06-14T13:34:24Z")

</div>

shrink-ray-current package

---

<div class="post-metadata">

**Author:** ![bbarnhill](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/bbarnhill/32/5190_2.png) [@bbarnhill](https://community.apollographql.com/u/bbarnhill)\
**Post date:** [June 25, 2024, 6:49pm UTC](https://community.apollographql.com/t/compression-middleware/436/6 "2024-06-25T18:49:59Z")

</div>

Has anyone heard any update on this? We have looked at using Brotli and cant due to the underlying Express.js limitation.
