0
0
SASSmarkup~8 mins

String types and concatenation in SASS - Performance & Optimization

Choose your learning style9 modes available
Performance: String types and concatenation
MEDIUM IMPACT
This affects CSS generation speed and final CSS file size, impacting page load and render time.
Combining multiple strings to form CSS property values
SASS
$color: "red blue green";
Using a single string literal avoids repeated concatenation operations, making compilation faster.
📈 Performance GainSingle string operation, reducing compile time and CSS output size
Combining multiple strings to form CSS property values
SASS
$color: "red" + " " + "blue" + " " + "green";
Using multiple '+' operators for string concatenation creates unnecessary intermediate strings and slows down Sass compilation.
📉 Performance CostTriggers multiple string operations, increasing compile time linearly with number of concatenations
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Multiple '+' concatenations in Sass0 (preprocessing only)00[X] Bad
Single string literal000[OK] Good
Interpolation with #{}000[OK] Good
Rendering Pipeline
Sass string concatenation happens during the pre-processing stage before CSS is sent to the browser. Efficient concatenation reduces CSS file size, which speeds up network transfer and parsing by the browser.
Preprocessing
Network Transfer
CSS Parsing
⚠️ BottleneckPreprocessing string operations can slow down build time; large CSS files increase network and parsing time.
Core Web Vital Affected
LCP
This affects CSS generation speed and final CSS file size, impacting page load and render time.
Optimization Tips
1Use single string literals instead of multiple '+' concatenations in Sass.
2Prefer interpolation (#{} ) for combining variables and strings to reduce compile overhead.
3Smaller CSS output from efficient concatenation improves page load and LCP.
Performance Quiz - 3 Questions
Test your performance knowledge
Which Sass string concatenation method generally results in faster compilation?
AConcatenating strings with JavaScript after compilation
BUsing multiple '+' operators to join strings
CUsing a single string literal
DUsing CSS variables instead of Sass strings
DevTools: Network
How to check: Open DevTools, go to Network tab, reload page, and inspect CSS file size and load time.
What to look for: Smaller CSS file size and faster load time indicate efficient Sass string handling.