Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

CSS Performance – Critical CSS & Unused | CSS Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Course

Lesson 38 of 50

·css

CSS Performance – Critical CSS & Unused CSS

9 mins

Course progress76%

What you'll learn

Keep this idea in mind as you work through the lesson.

1 point
  • `rel="preload"` + `onload` trick loads the full stylesheet **asynchronously**. * Tools like **PurgeCSS** strip unused selectors (especially useful with frameworks). * Keep the **selector chain short**; deep nesting hurts performance.

Critical CSS is the minimal set of styles needed for above‑the‑fold content.

  • Extract it manually or with tools like Critical, PurgeCSS, UnCSS.
  • Inline critical CSS in the <head> to avoid a render‑blocking request.
  • Load the rest of the stylesheet with rel="preload" + as="style" and change to rel="stylesheet" on onload.

Example: Inline critical CSS + preload

<style>
  .hero{background:#333;color:#fff;padding:4rem;text-align:center;}
</style>
<link rel="preload" href="/css/main.css" as="style" onload="this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="/css/main.css"></noscript>
Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS CourseBrowse activities
Previous lessonCSS for EmailContinue to lesson 39CSS Architecture – BEM, OOCSS, SMACSS, ITCSSBack to CSS Course curriculum