0
0
SASSmarkup~8 mins

@forward directive for re-exporting in SASS - Performance & Optimization

Choose your learning style9 modes available
Performance: @forward directive for re-exporting
MEDIUM IMPACT
This affects CSS build time and bundle size by controlling how styles are combined and re-exported.
Combining multiple Sass partials into a single stylesheet for reuse
SASS
@forward 'buttons';
@forward 'forms';
@forward 'layout';
Re-exports styles without duplication, allowing better tree shaking and smaller bundles.
📈 Performance Gainreduces CSS bundle size, speeds up build and page load
Combining multiple Sass partials into a single stylesheet for reuse
SASS
@import 'buttons';
@import 'forms';
@import 'layout';
Imports duplicate CSS and can cause larger bundle size and slower build times.
📉 Performance Costadds unnecessary CSS to bundle, increasing file size and blocking rendering longer
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Using multiple @import statementsNo direct DOM impactNo direct reflowsHigher paint cost due to larger CSS[X] Bad
Using @forward to re-export stylesNo direct DOM impactNo direct reflowsLower paint cost due to smaller CSS[OK] Good
Rendering Pipeline
The @forward directive affects the CSS build step before the browser rendering pipeline. It controls which styles are included in the final CSS file, impacting how much CSS the browser must parse and paint.
Build Time
Network Transfer
Style Calculation
Paint
⚠️ BottleneckNetwork Transfer and Style Calculation due to larger CSS files
Core Web Vital Affected
LCP
This affects CSS build time and bundle size by controlling how styles are combined and re-exported.
Optimization Tips
1Use @forward to combine Sass modules without duplicating CSS.
2Avoid multiple @import statements that include the same styles repeatedly.
3Smaller CSS bundles improve Largest Contentful Paint (LCP) and page load speed.
Performance Quiz - 3 Questions
Test your performance knowledge
How does using @forward instead of multiple @import statements affect CSS bundle size?
AIt reduces bundle size by avoiding duplicate CSS
BIt increases bundle size by adding more CSS
CIt has no effect on bundle size
DIt removes all CSS from the bundle
DevTools: Network
How to check: Open DevTools, go to Network tab, reload page, and check CSS file size and load time.
What to look for: Smaller CSS file size and faster load time indicate better use of @forward.