0
0
Remixframework~8 mins

CSS imports per route in Remix - Performance & Optimization

Choose your learning style9 modes available
Performance: CSS imports per route
MEDIUM IMPACT
This affects the page load speed by controlling how much CSS is loaded initially and when navigating between routes.
Loading CSS styles in a Remix app for each route
Remix
import './global.css';

export function links() {
  return [{ rel: 'stylesheet', href: '/global.css' }];
}

// In routeA.jsx
import './routeA.css';
export function links() {
  return [{ rel: 'stylesheet', href: '/routeA.css' }];
}

// In routeB.jsx
import './routeB.css';
export function links() {
  return [{ rel: 'stylesheet', href: '/routeB.css' }];
}
Each route loads only its CSS, reducing initial load and speeding up rendering.
📈 Performance GainReduces CSS payload per route by 30-70kb, improves LCP by 100-300ms on average.
Loading CSS styles in a Remix app for each route
Remix
import './global.css';
import './routeA.css';
import './routeB.css';

export function links() {
  return [
    { rel: 'stylesheet', href: '/global.css' },
    { rel: 'stylesheet', href: '/routeA.css' },
    { rel: 'stylesheet', href: '/routeB.css' }
  ];
}
All CSS files load on every route, increasing bundle size and delaying page rendering.
📉 Performance CostBlocks rendering longer, increases CSS payload by 50-100kb depending on styles, delays LCP.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Global CSS import for all routesMinimal1 per route loadHigh due to large CSS[X] Bad
Route-specific CSS importsMinimal1 per route loadLow due to smaller CSS[OK] Good
Rendering Pipeline
CSS imports per route affect the critical rendering path by controlling which CSS files are requested and parsed before painting the page.
Style Calculation
Layout
Paint
⚠️ BottleneckStyle Calculation due to large CSS files blocking rendering
Core Web Vital Affected
LCP
This affects the page load speed by controlling how much CSS is loaded initially and when navigating between routes.
Optimization Tips
1Import only the CSS needed for each route to reduce initial load.
2Avoid importing all CSS globally to prevent blocking rendering.
3Use Remix's links function per route to control CSS loading.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of importing CSS per route in Remix?
AIncreases CSS bundle size for caching
BImproves JavaScript execution speed
CReduces initial CSS payload and speeds up Largest Contentful Paint
DReduces server response time
DevTools: Network and Performance panels
How to check: Open DevTools, go to Network tab, filter by CSS, and observe which CSS files load on each route. Use Performance tab to record page load and check LCP timing.
What to look for: Look for large CSS files loading on all routes (bad) vs only route-specific CSS loading (good). Check LCP marker for faster paint.