Enabling Brotli Compression
nikumar1206
HOBBYOP

3 months ago

Hi everyone,

I have an Nginx proxy sitting in front of my frontend assets, configured to serve pre-compressed brotli-compressed assets to the browser.

When targeting against my local, it works just fine.

When targeting against Railway, it doesn't :(

some response headers i captured against railway:

content-length 417694

content-type application/javascript

etag "69a662e7-65f9e"

server railway-edge

vary Accept-Encoding

via 1.1 varnish

x-cache MISS

x-cache-hits 0

x-content-type-options nosniff

x-frame-options SAMEORIGIN

x-railway-cdn-edge fastly/cache-nyc-kteb1890065-NYC

x-railway-edge railway/us-east4-eqdc4a

x-railway-request-id PIaxEB-8RLqltvbdPvyhXg

x-timer S1772513253.330495,VS0,VE9

x-xss-protection 1; mode=block

The request does include 'br' in the Accept-Encoding header.

trying via curl and only setting 'br' in the encoding header does not work either::

curl -I -H "Accept-Encoding: br" https://loco.build/assets/index-C%5FAp9zAR.js

HTTP/2 200

accept-ranges: bytes

cache-control: max-age=31536000, public, immutable

content-type: application/javascript

but doing a similar command against my local, which is running the nginx proxy directly does:

curl -I -H "Accept-Encoding: br" http://localhost:8080/assets/index-DzVGT748.js

HTTP/1.1 200 OK

Server: nginx

Date: Tue, 03 Mar 2026 05:01:02 GMT

Content-Type: application/javascript

Content-Length: 95332

Last-Modified: Tue, 03 Mar 2026 03:57:17 GMT

Connection: keep-alive

ETag: "69a65c1d-17464"

Content-Encoding: br

Is this something due to the railway edge-proxy/fastly-edge?

$10 Bounty

1 Replies

Status changed to Awaiting Railway Response Railway 3 months ago


neobee714
FREE

3 months ago

hello,nikumar1206.

To perfectly adapt to Railway's edge network environment, we recommend you make the following adjustments:

Verify hypothesis (optional):

You can print the internal request variable $http_accept_encoding in the log format definition (log_format) of Nginx. You will visually see that after passing through the Railway proxy, the header actually received by Nginx no longer contains "br".

Fix Nginx headers:

Ensure to manually add the add_header directive in your Nginx configuration: add_header Vary Accept-Encoding;. This is a mandatory rule to declare content negotiation to all upstream CDNs.

Add a Gzip backup solution (highly recommended):

Since Railway/Fastly may downgrade Brotli requests at the edge layer, it is recommended that you package both .gz and .br files in the frontend build output, and enable gzip_static on in Nginx. This way, even if the CDN forces your request to be downgraded to Gzip, Nginx will return a compressed file of tens of kilobytes, rather than an uncompressed giant of 417KB.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...