Setting up Brotli compression for 1C-Bitrix

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Configuring Brotli Compression for 1C-Bitrix

Configuring Brotli Compression for 1C-Bitrix

Gzip at level 6 compresses a typical catalog page HTML from 180 KB to 32 KB. Brotli at level 11 delivers 27–28 KB at the same CPU cost — a 15–20% gain without any code changes. For CSS and JS the difference is even more pronounced: a 400 KB bundle is 110 KB after Gzip and 90–95 KB after Brotli. On slow mobile connections, this is noticeable.

All modern browsers support Brotli (br in the Accept-Encoding header). Brotli requires HTTPS — by specification it only works over a secure connection.

Installing the Brotli Module for nginx

nginx does not support Brotli out of the box — the ngx_brotli module is required. Two options:

Compile from source:

# Clone the module
cd /usr/local/src
git clone --recurse-submodules https://github.com/google/ngx_brotli.git

# Check nginx version
nginx -v

# Download sources of the same version
wget http://nginx.org/download/nginx-1.24.0.tar.gz
tar -xzf nginx-1.24.0.tar.gz
cd nginx-1.24.0

# Configure with the module
./configure --with-compat --add-dynamic-module=/usr/local/src/ngx_brotli

# Build only modules
make modules

# Copy .so files to the nginx modules directory
cp objs/ngx_http_brotli_filter_module.so /etc/nginx/modules/
cp objs/ngx_http_brotli_static_module.so /etc/nginx/modules/

Pre-built package (Debian/Ubuntu):

add-apt-repository ppa:ondrej/nginx
apt update
apt install libnginx-mod-http-brotli

nginx Configuration for Bitrix

# /etc/nginx/nginx.conf — inside the http block
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;

http {
    # Brotli dynamic compression
    brotli on;
    brotli_comp_level 6;
    brotli_types
        text/html
        text/css
        text/javascript
        application/javascript
        application/json
        application/xml
        text/xml
        image/svg+xml
        font/woff2;

    # Static pre-compressed files
    brotli_static on;

    # Gzip as fallback for browsers without Brotli support
    gzip on;
    gzip_comp_level 6;
    gzip_types text/html text/css application/javascript;
    gzip_vary on;
}

brotli_comp_level 6 — balance between compression ratio and CPU load. Level 11 gives +5–8% compression at 10x the compression time cost — justified only for pre-compressed static assets.

brotli_static on — nginx looks for assets/app.js.br alongside assets/app.js. If found, it serves the pre-built archive with no CPU cost.

Pre-compressed Files for Bitrix Static Assets

For CSS/JS bundles that rarely change, prepare .br files in advance:

# Install brotli CLI
apt install brotli

# Compress all JS and CSS in the public directory
find /var/www/bitrix/public -name "*.js" -o -name "*.css" | while read f; do
    brotli --best --keep "$f"
done

Add to the deploy script: after building the frontend, automatically generate .br files.

Verifying the Setup

curl -sI -H "Accept-Encoding: br" https://site.ru/bitrix/js/main/core/core.js | grep -i content-encoding
# Expected response: Content-Encoding: br

# Compare sizes
curl -s -H "Accept-Encoding: identity" https://site.ru/css/app.css | wc -c
curl -s -H "Accept-Encoding: br" https://site.ru/css/app.css | wc -c

Apache mod_brotli

If Bitrix runs on Apache without an nginx front end:

LoadModule brotli_module modules/mod_brotli.so

<IfModule mod_brotli.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/css application/javascript
    BrotliCompressionLevel 6
</IfModule>

mod_brotli is included in Apache 2.4.26+. On older Bitrix environment servers (Apache 2.2), Brotli is unavailable — an upgrade or migration to nginx is required.