Bird
Raised Fist0
Remixframework~8 mins

CSS imports per route in Remix - Performance & Optimization

Choose your learning style10 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.

Practice

(1/5)
1. In Remix, how do you add CSS styles that apply only to a specific route?
easy
A. By exporting a links function that returns CSS links from the route file
B. By importing CSS files directly inside the component's JSX
C. By adding CSS inside a global stylesheet only
D. By using inline styles on every HTML element

Solution

  1. Step 1: Understand Remix route styling

    Remix uses a special links export in route files to load CSS only for that route.
  2. Step 2: Why links is preferred

    This method keeps styles scoped and improves loading by only fetching needed CSS.
  3. Final Answer:

    By exporting a links function that returns CSS links from the route file -> Option A
  4. Quick Check:

    Route CSS = links export [OK]
Hint: Use links export in route files for CSS [OK]
Common Mistakes:
  • Importing CSS inside JSX instead of using links
  • Adding all CSS globally instead of per route
  • Using inline styles everywhere
2. Which of the following is the correct syntax to import a CSS file in a Remix route using the links function?
easy
A. export const links = () => [{ rel: 'stylesheet', href: './styles.css' }];
B. import './styles.css';
C. export default function links() { return ; }
D. export function links() { return { rel: 'stylesheet', href: './styles.css' }; }

Solution

  1. Step 1: Identify correct links export syntax

    Remix expects links as a function returning an array of objects with rel and href.
  2. Step 2: Check arrow function usage

    export const links = () => [{ rel: 'stylesheet', href: './styles.css' }]; uses an arrow function returning the correct array format, which is valid and common.
  3. Final Answer:

    export const links = () => [{ rel: 'stylesheet', href: './styles.css' }]; -> Option A
  4. Quick Check:

    Arrow function returning array = export const links = () => [{ rel: 'stylesheet', href: './styles.css' }]; [OK]
Hint: Use arrow function returning array of link objects [OK]
Common Mistakes:
  • Using default export instead of named export
  • Returning JSX instead of array
  • Importing CSS directly without links function
3. Given this Remix route code, what CSS files will be loaded when visiting this route?
import styles from '~/styles/page.css';

export const links = () => [
  { rel: 'stylesheet', href: styles }
];
medium
A. No CSS will load because styles is imported incorrectly
B. The CSS file at '~/styles/page.css' will be loaded
C. All CSS files in the styles folder will load
D. Only global CSS will load, not this file

Solution

  1. Step 1: Understand CSS import in Remix

    Importing CSS as styles gives the path string for the CSS file.
  2. Step 2: Check links usage

    The links function returns an array with the CSS file href set to styles, so it loads that CSS file.
  3. Final Answer:

    The CSS file at '~/styles/page.css' will be loaded -> Option B
  4. Quick Check:

    Imported CSS path used in links = The CSS file at '~/styles/page.css' will be loaded [OK]
Hint: Imported CSS path used in links loads that file [OK]
Common Mistakes:
  • Thinking import gives CSS content, not path
  • Assuming all folder CSS loads automatically
  • Confusing global CSS with route CSS
4. Identify the error in this Remix route CSS import code:
export function links() {
  return {
    rel: 'stylesheet',
    href: '/styles.css'
  };
}
medium
A. The href path must be relative, not absolute
B. The rel attribute should be 'style' instead of 'stylesheet'
C. The function should be named Links with uppercase L
D. The links function should return an array, not an object

Solution

  1. Step 1: Check return type of links

    Remix expects links to return an array of link objects, not a single object.
  2. Step 2: Validate other attributes

    The href and rel values are correct; only the return type is wrong.
  3. Final Answer:

    The links function should return an array, not an object -> Option D
  4. Quick Check:

    links returns array = The links function should return an array, not an object [OK]
Hint: Return an array of link objects in links [OK]
Common Mistakes:
  • Returning a single object instead of array
  • Incorrect function name casing
  • Wrong rel attribute value
5. You want to load two CSS files, base.css and theme.css, only on a specific Remix route. How should you write the links function to achieve this?
hard
A. import base from './base.css'; import theme from './theme.css'; export function links() { return [base, theme]; }
B. export const links = () => ({ rel: 'stylesheet', href: '/base.css', rel: 'stylesheet', href: '/theme.css' });
C. export const links = () => [ { rel: 'stylesheet', href: '/base.css' }, { rel: 'stylesheet', href: '/theme.css' } ];
D. export function links() { return <> </>; }

Solution

  1. Step 1: Understand multiple CSS imports in links

    The links function must return an array of objects, each with rel and href.
  2. Step 2: Check each option's correctness

    export const links = () => [ { rel: 'stylesheet', href: '/base.css' }, { rel: 'stylesheet', href: '/theme.css' } ]; correctly returns an array with two link objects. Others either return an object, JSX, or invalid array contents.
  3. Final Answer:

    export const links = () => [ { rel: 'stylesheet', href: '/base.css' }, { rel: 'stylesheet', href: '/theme.css' } ]; -> Option C
  4. Quick Check:

    Array of link objects = export const links = () => [ { rel: 'stylesheet', href: '/base.css' }, { rel: 'stylesheet', href: '/theme.css' } ]; [OK]
Hint: Return array with multiple link objects in links [OK]
Common Mistakes:
  • Returning a single object with duplicate keys
  • Returning JSX instead of array
  • Returning array of strings instead of objects
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard