Performance: Global styles and CSS frameworks
This concept affects page load speed and rendering performance by controlling how CSS is loaded and applied globally across the site.
/* src/layouts/Layout.jsx */ import './styles/global.css'; // global.css contains only essential base styles and critical utilities export default function Layout({ children }) { return <html><body>{children}</body></html>; }
/* src/layouts/Layout.jsx */ import 'bulma/css/bulma.css'; // Importing entire Bulma CSS framework globally in the main layout export default function Layout({ children }) { return <html><body>{children}</body></html>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full CSS framework globally | Low (CSS only) | 0 immediate, but blocks layout | High due to large CSS size | [X] Bad |
| Minimal global CSS with critical styles | Low | 0 immediate | Low paint cost | [OK] Good |
import './styles/global.css';.<link rel="stylesheet" href="./styles/global.css" /> inside src/pages/index.astro uses HTML link tag which can work but is less common in Astro root layouts. @import './styles/global.css'; inside a JavaScript file uses CSS syntax incorrectly in JS. require('./styles/global.css'); inside a component script uses CommonJS require which is not valid in Astro's ES module environment.import './styles/global.css'; inside a component script -> Option C---
import '../styles/global.css';
---
global.css contains:body { background-color: #f0f0f0; }global.css in the root layout applies its styles to the whole page, including the body tag.body { background-color: #f0f0f0; }, which is a light gray color.import 'tailwindcss/tailwind.css'; in a component, but styles don't apply. What is the likely issue?<head> ensures all pages get the styles.Pass the test and this pattern moves unknown