HTML & CSS Interview Question #34

What are the preload and preconnect resource hints?

Forms, Validation, Metadata, Media, Responsive Images & Accessibility Junior Beginner

Quick Interview Answer

preload tells the browser that a specific resource will be needed soon for the current page and should be fetched with appropriate priority. preconnect asks the browser to establish an early connection to another origin before a resource request is made.

Detailed Explanation

preload tells the browser that a specific resource will be needed soon for the current page and should be fetched with appropriate priority. preconnect asks the browser to establish an early connection to another origin before a resource request is made.

These hints can improve performance when used for genuinely critical resources, but excessive or incorrect hints can waste bandwidth and connection capacity. They should be introduced based on measured performance needs.

Code Example

<link rel="preconnect"
      href="https://fonts.example.com">

<link rel="preload"
      href="/fonts/site.woff2"
      as="font"
      type="font/woff2"
      crossorigin>