Skip to main content

Lesson 3 of 9

Performance & Optimization

Optimize HTML for performance - critical rendering path, resource hints (preload, prefetch, preconnect), lazy loading, and Core Web Vitals optimization.

30 minBy Priygop Editorial TeamUpdated 2026Peer Reviewed & Verified

HTML Performance Techniques

  • <link rel='preconnect'> - Establish early connection to critical third-party domains (fonts, CDN, API). Saves DNS + TCP + TLS time
  • <link rel='preload'> - Force early loading of critical resources (hero image, main CSS, key font). as attribute specifies type
  • <link rel='prefetch'> - Low-priority fetch for resources needed on the next page. Good for predictive loading
  • loading='lazy' - Defer images and iframes below the fold. Never lazy-load above-the-fold content (hurts LCP)
  • async/defer on scripts - async loads and executes ASAP (non-blocking). defer loads in parallel, executes after HTML parsing
  • Critical CSS - Inline the CSS needed for above-the-fold content in <style> tag. Load remaining CSS asynchronously

Resource Hints Code

Resource Hints Code
<head>
  <!-- Preconnect to third-party origins -->
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://cdn.example.com" crossorigin>

  <!-- Preload critical resources -->
  <link rel="preload" href="/fonts/Inter.woff2" as="font" type="font/woff2" crossorigin>
  <link rel="preload" href="/hero-image.webp" as="image">
  <link rel="preload" href="/critical.css" as="style">

  <!-- Prefetch next page resources -->
  <link rel="prefetch" href="/about.html">
  <link rel="prefetch" href="/about-hero.webp" as="image">

  <!-- Critical CSS inlined -->
  <style>
    /* Only styles needed for above-the-fold content */
    body { margin: 0; font-family: 'Inter', sans-serif; }
    .hero { min-height: 50vh; display: flex; align-items: center; }
  </style>

  <!-- Non-critical CSS loaded asynchronously -->
  <link rel="preload" href="/full-styles.css" as="style" onload="this.onload=null;this.rel='stylesheet'">

  <!-- Scripts: defer for non-critical -->
  <script src="/analytics.js" async></script>
  <script src="/app.js" defer></script>
</head>

Pro Tip

Don't preload everything - only preload resources critical for the first paint (hero image, main font, critical CSS). Over-preloading wastes bandwidth and can actually slow things down because the browser prioritizes preloaded resources over other important resources it discovers naturally.

Diagram
Loading diagram…

Optimize asset loading to minimize render-blocking time and speed up page renders

Quick Quiz: Performance

Key Takeaways

  • Optimize HTML for performance - critical rendering path, resource hints (preload, prefetch, preconnect), lazy loading, and Core Web Vitals optimization.
  • <link rel='preconnect'> - Establish early connection to critical third-party domains (fonts, CDN, API). Saves DNS + TCP + TLS time
  • <link rel='preload'> - Force early loading of critical resources (hero image, main CSS, key font). as attribute specifies type
  • <link rel='prefetch'> - Low-priority fetch for resources needed on the next page. Good for predictive loading

Hands-on Practice Tools for this Course

Test what you learn using these free in-browser developer utilities (no signup required).

All 40+ Tools

Topics in This Module

0/9 done