CSS and JS Compression Configuration for 1C-Bitrix
Without compression, the CSS and JS files of a Bitrix project are delivered to the client at their original size. For a typical project this totals 500 KB–2 MB. Gzip or Brotli compression reduces the volume of transferred data by a factor of 3–7 for text resources — making it one of the easiest performance wins to implement.
Bitrix Built-in Compression Tools
Bitrix includes its own minification and bundling mechanism for CSS/JS, accessible at Settings → Performance → Compression. It operates at the PHP level: it collects files registered via CMain::AddCSSLink() and CMain::AddHeadScript(), minifies them, and stores the results in /bitrix/cache/css/ and /bitrix/cache/js/. The resulting files have a hash in their filename — browsers cache them aggressively.
Important: Bitrix minification only processes files registered through the Bitrix API. CSS and JS included directly in templates via <link> and <script> tags are not processed. On legacy projects, it is common for half the files to bypass the API entirely.
Compression at the nginx Level
Minification reduces file size, but transfer-level compression (gzip/Brotli) is a separate concern. nginx configuration:
gzip on;
gzip_types text/css application/javascript application/json text/javascript;
gzip_min_length 1024;
gzip_comp_level 5;
gzip_vary on;
gzip_comp_level 5 is a balance between compression ratio and CPU load. Levels 6–9 yield minimal additional compression with significantly higher CPU usage. gzip_vary on adds the Vary: Accept-Encoding header, which is required for correct behavior with caching proxies and CDNs.
What to Check During Setup
A common mistake: gzip is enabled in nginx, but PHP-FPM or Bitrix itself also compresses the response — resulting in double compression. The symptom is a browser decoding error or a file downloading instead of executing. Verify with curl -I -H "Accept-Encoding: gzip" https://mysite.com/bitrix/cache/css/file.css — the response headers must include Content-Encoding: gzip.
For minified files with a hash in the filename, configure static (pre-compressed) delivery via gzip_static on — nginx serves a pre-compressed .gz file with no CPU overhead at runtime.
Case Study and Typical Results
A corporate Bitrix "Standard" site with 12 CSS and 23 JS files registered through the API. After enabling Bitrix minification and gzip in nginx: total CSS+JS size dropped from 1.4 MB to 180 KB (after minification) → 48 KB (after gzip). HTTP requests to CSS decreased from 12 to 2, to JS from 23 to 3. Time to DOMContentLoaded dropped by 0.8 s on 3G mobile connections.
Setup takes 4–8 hours: auditing how CSS/JS is included, migrating direct includes to the Bitrix API, enabling minification, configuring gzip in nginx, and verifying the absence of double compression.







