Performance: Bootstrap SASS variable overrides
This affects CSS bundle size and render-blocking time during page load by customizing Bootstrap styles at build time.
$primary: #123456; @import 'bootstrap'; /* Override SASS variable before importing Bootstrap to generate only needed CSS */
@import 'bootstrap'; body { --bs-primary: #123456; } /* Override colors using CSS variables after loading full Bootstrap CSS */
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Override CSS variables after loading full Bootstrap CSS | No change | 0 | High due to large CSS | [X] Bad |
| Override SASS variables before compiling Bootstrap | No change | 0 | Lower due to smaller CSS | [OK] Good |
$primary color?$primary before the import, Bootstrap uses the new value instead of the default.$primary before importing Bootstrap's SASS files -> Option A$font-size-base to 1.25rem?$variable-name: value; syntax without equals sign or !default when overriding.$font-size-base: 1.25rem; before importing Bootstrap.$btn-primary-bg: #ff0000; @import 'bootstrap';
$btn-primary-bg is set to red before importing Bootstrap, so Bootstrap uses this value.$btn-primary-bg for the primary button background color.$spacer to 3rem but your Bootstrap layout spacing did not change. What is the most likely mistake?$spacer after importing Bootstrap has no effect because variables must be set before import.$primary and $font-size-base before importing Bootstrap -> Option CPass the test and this pattern moves unknown