0Pricing
Next.js 15 Fullstack Web Apps · Lección

Optimización de imágenes y fuentes

Optimice las imágenes con `next/image` y gestione las fuentes de forma eficiente para reducir los tiempos de carga.

Optimización de imágenes y fuentes es una lección gratuita de Next.js 15 Fullstack Web Apps en CoddyKit. Esta es la lección 2 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Next.js 15 Fullstack Web Apps, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Next.js 15 Fullstack Web Apps incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

Why Optimize Images & Fonts?

Optimizing images and fonts is crucial for a fast-loading website. Large files slow down your page, impacting user experience and SEO.

  • Faster Loading: Users don't wait for slow pages.
  • Improved SEO: Search engines favor faster sites.
  • Better UX: Smooth, responsive feel.
  • Lower Bandwidth: Saves data for users.

Next.js Image Component

Next.js provides a powerful next/image component. It automatically optimizes images for you, handling responsiveness, lazy loading, and format conversion to modern formats like WebP.

Using next/image ensures your images are served in the most efficient way possible, often without you needing to do manual optimization.

Using the Image Component

To use next/image, import it and then define your image's src, alt text, width, and height. The width and height are crucial for preventing layout shifts (CLS).

import Image from 'next/image';

export default function MyImage() {
  return (
    <Image
      src="/my-photo.jpg"
      alt="A descriptive alt text"
      width={500}
      height={300}
    />
  );
}

Layout Modes & Responsiveness

next/image offers different layout modes to control how images scale:

  • intrinsic (default): Scales down for smaller viewports, but doesn't scale up beyond its original size.
  • fixed: Image is fixed width and height.
  • fill: Image fills its parent element, useful for background images or when the image dimensions are unknown. Requires the parent to have position: relative.

Loading Priority with `priority`

For images above the fold (visible when the page first loads), you should add the priority prop. This tells Next.js to preload the image, improving your site's Largest Contentful Paint (LCP) metric.

Only use priority for critical images, like hero banners. Overusing it can negate its benefits.

import Image from 'next/image';

export default function HeroSection() {
  return (
    <Image
      src="/hero-banner.jpg"
      alt="Hero banner for the website"
      width={1200}
      height={600}
      priority
    />
  );
}

The Need for Font Optimization

Custom fonts can significantly impact performance. Large font files mean longer download times, leading to 'flash of unstyled text' (FOUT) or 'flash of invisible text' (FOIT).

Optimizing fonts reduces file size and ensures they load smoothly, improving the visual experience and preventing layout shifts.

Google Fonts with `next/font`

Next.js 15 simplifies using Google Fonts with next/font/google. It automatically self-hosts fonts, reduces layout shifts (CLS), and improves privacy by avoiding direct requests to Google.

Import your desired font, then apply it to your HTML elements.

import { Inter } from 'next/font/google';

// Configure the Inter font
const inter = Inter({ subsets: ['latin'] });

export default function MyApp({ Component, pageProps }) {
  return (
    <main className={inter.className}>
      <Component {...pageProps} />
    </main>
  );
}

Self-Hosting Local Fonts

For self-hosted fonts (fonts you provide yourself), use next/font/local. This allows you to bundle your font files directly with your application, giving you full control over their delivery.

Define your font source and apply it just like Google Fonts.

import localFont from 'next/font/local';

// Configure a local custom font
const myCustomFont = localFont({ src: './my-custom-font.woff2' });

export default function MyPage() {
  return (
    <h1 className={myCustomFont.className}>
      My Custom Title
    </h1>
  );
}

Font Loading Strategies

To further optimize font loading:

  • display: swap: This CSS property shows fallback text immediately while the custom font loads, preventing 'flash of invisible text' (FOIT). next/font handles this by default.
  • Subset Fonts: Only include the characters you need from a font to reduce file size.
  • Preload Critical Fonts: For your most important fonts, consider preloading them using <link rel="preload"> in your document's head.

Image Optimization Check

Which of the following are benefits of using the next/image component in a Next.js application?

Recap: Optimized for Performance

Great job! You've learned how to significantly boost your Next.js app's performance by optimizing images and fonts.

  • Use next/image for automatic image optimization, lazy loading, and layout shift prevention.
  • Leverage the priority prop for critical above-the-fold images.
  • Utilize next/font/google and next/font/local for efficient, self-hosted font loading, which also prevents layout shifts.

These practices lead to faster, more user-friendly applications.

Preguntas frecuentes

¿La lección «Optimización de imágenes y fuentes» es gratis?

Sí — el texto completo de «Optimización de imágenes y fuentes» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Next.js 15 Fullstack Web Apps, actualiza a CoddyKit PRO. El curso de Next.js 15 Fullstack Web Apps incluye 4 lecciones en total.

¿Qué aprenderé en «Optimización de imágenes y fuentes»?

Optimice las imágenes con `next/image` y gestione las fuentes de forma eficiente para reducir los tiempos de carga. Practicas Next.js 15 Fullstack Web Apps con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar Next.js 15 Fullstack Web Apps?

No se requiere experiencia previa. Next.js 15 Fullstack Web Apps en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 2 de 4.

¿Cuánto tiempo toma la lección «Optimización de imágenes y fuentes»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de Next.js 15 Fullstack Web Apps?

Sí. Cada lección de Next.js 15 Fullstack Web Apps incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. Despliegue en Vercel y Netlify
  2. Optimización de imágenes y fuentes
  3. Análisis del bundle y auditorías de rendimiento
  4. Core Web Vitals y monitorización
← Volver a Next.js 15 Fullstack Web Apps