Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Performanceintermediate

Prefetch Setup

Share

Set up resource prefetching and preloading

Works with OpenClaude

You are a web performance engineer. The user wants to set up resource prefetching and preloading to improve page load times and perceived performance.

What to check first

  • Inspect <head> section of your HTML to see existing <link> tags
  • Run Chrome DevTools Network tab to identify which resources are critical path blockers
  • Check your bundle size with webpack-bundle-analyzer or similar to prioritize what to prefetch

Steps

  1. Add <link rel="preload"> tags for critical resources in the <head> with as attribute matching resource type (e.g., as="font", as="script", as="style")
  2. Use <link rel="prefetch"> for non-critical resources that the user will likely need on next navigation
  3. Add <link rel="dns-prefetch"> for third-party domains (e.g., analytics, CDN) to resolve DNS early
  4. Use <link rel="preconnect"> for domains where you'll fetch resources to establish TCP connection and TLS handshake
  5. Implement resource hints with crossorigin attribute when fetching cross-origin resources to match CORS requirements
  6. Use <link rel="preload"> with onload="this.onload=null;this.rel='stylesheet'" to load stylesheets without blocking render
  7. Add <link rel="prefetch"> in a service worker or JavaScript for dynamic route prefetching
  8. Test with DevTools Coverage tab to ensure prefetched resources are actually used

Code

<!DOCTYPE html>
<html lang="en">
<head>
  <!-- Preload critical font with crossorigin -->
  <link rel="preload" href="/fonts/inter-var.woff2" as="font" type="font/woff2" crossorigin>
  
  <!-- Preload critical CSS -->
  <link rel="preload" href="/css/critical.css" as="style">
  
  <!-- Preload hero image -->
  <link rel="preload" href="/images/hero.webp" as="image" media="(min-width: 1024px)">
  
  <!-- DNS prefetch for third-party analytics -->
  <link rel="dns-prefetch" href="//cdn.example.com">
  
  <!-- Preconnect to API server -->
  <link rel="preconnect" href="https://api.example.com" crossorigin>
  
  <!-- Prefetch next page resources (for SPA navigation) -->
  <link rel="prefetch" href="/js/about-page.js">
  <link rel="prefetch" href="/js/products-page.js">
  
  <!-- Load stylesheet without blocking render -->
  <link rel="preload" href="/css/main.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
  <noscript><link rel="stylesheet" href="/css/main.css"></n

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryPerformance
Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
performanceprefetchpreload

Install command:

curl -o ~/.claude/skills/prefetch-setup.md https://claude-skills-hub.vercel.app/skills/performance/prefetch-setup.md

Related Performance Skills

Other Claude Code skills in the same category — free to download.

Want a Performance skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.