Entendiendo el rendimiento

1

Todo lo que aprenderás sobre optimización web

2

¿Vale el esfuerzo optimizar un sitio web?

3

¿Cuándo realmente un sitio es rápido o lento?

Antes de optimizar...

4

Aprendiendo a medir

5

User Performance Metrics

6

Nuestro proyecto

Crítical Rendering Path

7

Etapas de render del navegador

8

Network waterfall y recursos que bloquean el navegador

9

Priorización de recursos

10

Preloading y prefetching de recursos

11

Fases Paint y Layout del Critical Render Path

CSS

12

Detectando Paints costosos y optimizando animaciones

13

Bloqueos y complejidad en selectores

WebFonts

14

WebFonts y su impacto en rendimiento

Imágenes, Iconos y SVG

15

Imágenes, formato y compresión

16

Imágenes y compresión

17

¿WebFont, Imagen o SVG?

18

Técnicas avanzadas con Lazy Loading

19

Técnicas avanzadas con Responsive Loading

Aplicaciones JavaScript

20

JavaScript y aplicaciones modernas y Utilizando un servidor de producción

21

Analizando el bundle de la aplicación

22

Reduciendo el tamaño del bundle

23

Code Splitting

24

Lazy Module Loading

25

Llevando los listeners a otro nivel

26

Instalando Modal video

27

Lazy loading del modal

28

Moviendo la carga de rendering hacia el servidor: Server Side Rendering

29

Aplicando SSR

30

Pre-renderizando el contenido: Static Generation

Caché

31

Cómo funciona el Caché de recursos y CDN

32

Deploy en Netlify y automatización de contenido en GitHub Actions

33

Aplicando Github Actions

34

Interceptando los requests del navegador con Service Workers

Performance Budget

35

Performance budget y auditorias automatizadas

36

Automatizando una auditoría con Lighthouse CI

37

Medidas reales y monitoreo constante

Conclusiones

38

Conclusiones

You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesión a prueba de IA

Antes: $249

Currency
$209
Suscríbete

Termina en:

2 Días
5 Hrs
8 Min
45 Seg

Preloading y prefetching de recursos

10/38
Resources

What are the strategies to improve the resource load on a browser?

To optimize the resource load of a web application, it is essential to understand how we can help the browser to anticipate and speed up these loads. Preload, prefetch and preconnect strategies allow us to tell the browser how to handle resource offloading, significantly improving performance and user experience. Below, we explore each strategy in detail.

What is preload and how does it work?

Preload is a technique that allows developers to tell the browser to offload a specific resource along with the HTML of the page. It is particularly useful when we know which resources are critical for the initial rendering of our application, thus allowing them to be ready as soon as possible.

  • Main advantage: It speeds up the loading of essential resources by loading them in parallel to the page load.
  • Implementation: It is done by using the <link rel="preload"> element in the HTML, specifying the exact resource that needs to be loaded.

What is prefetch for and when to use it?

Prefetch is another useful technique for improving performance, which suggests to the browser the possibility of needing a resource in the future. This strategy is more forward-looking and considers that the user might interact with page elements that require additional resources.

  • Use case: Ideal for resources that might be needed in subsequent interactions, such as navigating to another page or interacting with dynamic elements.
  • Execution: Employed using <link rel="prefetch">, anticipating possible but non-essential resources for the initial load.

How do Next.js and Gatsby optimize the network?

Next.js and Gatsby, two popular React frameworks, make aggressive and effective use of preload and prefetch. This is what makes them powerful options for applications with high performance demands:

  • Next.js: Implements preload efficiently through code splitting, dividing the JavaScript bundle into small modules that are loaded as needed.
  • Gatsby: Similarly, it optimizes prefetching by triggering preloading of resources when interacting with links, for example, by hovering over them.

What is preconnect all about?

Preconnect is a strategy that works at the connection level, allowing an early connection to be established to servers that will provide future resources. This saves time in the HTTP handshake, especially for external domains.

  • Practical applications: ideal for critical external domains, such as fonts, APIs, or CDN services.
  • Efficient usage: Implemented with <link rel="preconnect"> and optionally <link rel="dns-prefetch">, to resolve DNS and network connections before they are actually needed.

Practical examples of preconnect

To illustrate preconnect, in a typical project we might encounter the following connections:

  1. Google Fonts: connect through fonts.gstatic.com to get fonts quickly.
  2. External APIs: Like kitsu.io, used here to get data needed for specific functions of our application.
  3. Static or multimedia files: Using subdomains, such as media.kitsu.io, all under the same domain to simplify image loading.

In HTML, they would be implemented as follows:

<link rel="preconnect" href="https://fonts.gstatic.com" /><link rel="dns-prefetch" href="https://fonts.gstatic.com" /><link rel="preconnect" href="https://kitsu.io" /><link rel="dns-prefetch" href="https://kitsu.io" /> />

With these tools and techniques implemented, we significantly improve the performance of our web applications, enabling a smooth and fast user experience. It is crucial to experiment and adapt these strategies based on the specific behavior and needs of your application. Keep exploring and optimizing your projects!

Contributions 19

Questions 5

Sort by:

Want to see more contributions, questions and answers from the community?

Esto no tiene nada que ver con el curso, es un dato curioso. ¿Han notado que cada que inicia un video y aparece la palabra “Platzi” también hay una voz muy leve susurrandote "Platzi?

jaja Regalame tu like si devolviste el video para tratar de escuchar.

Pdta: Es Cierto 😄

Preload: Recurso que se descarga junto con el html
Prefetch: recurso que se descarga para un uso futuro
preconnect: conexión anticipada a recursos de servidores remotos.

🗃️ Preloading y prefetching de recursos

<h4>Ideas/conceptos claves</h4>

Preload. - Recurso que se descargue junto el HTML

Prefetch. - Recurso que en el futuro se podrá usar

Precconect. - Conexión anticipada a recursos de servidores remotos

<h4>Apuntes</h4>
  • Podemos decir al navegador cuales son los recursos y dominos que se debe conectar o descargar de forma anticipada
  • Existen 3 estrategias para poderlo hacerlo
    • Preload (recursos)
    • Prefetch (recursos)
    • Preconnect (dominios)
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin />
<link rel="dns-prefetch" href="https://fonts.gstatic.com/" />
  • podemos especificar con el atributo rel las estrategias para realizar este proceso

RESUMEN: Si le decimos al navegador de forma anticipada que recursos necesita o a que dominios se puede conectar de una forma anticipada podemos mejorar el rendimiento de nuestros sitios

    <link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin />
    <link rel="dns-prefetch" href="https://fonts.gstatic.com/" />
    <link rel="preconnect" href="https://kitsu.io/" crossorigin />
    <link rel="dns-prefetch" href="https://kitsu.io/" />

no comprendo porque Next.js llama scrip con link?

que buen curso platzi!.. me encanta la voz del profe

Si desean saber mas acerca de , dns-prefetch , les dejo el enlace , donde explica un poco mas del porque de esto , y habla un poco tambien de que hace el preconnect , esta interesante , se los recomiendo.

  1. Preload (recursos). Recursos que se descargan junto con el html.
  2. Prefetch (recursos). Recursos que se descargan para un uso futuro.
  3. Preconnect (dominios). Conexión anticipada a recursos de servidores remotos.
<h4>Preloading y prefetching de recursos</h4>

3 Estrategias:

  • Preload (recursos) se trata de un fetch declarativo en el que le decimos al navegador; "Este recurso tienes que descargarlo junto con el HTML.
  • Prefetch (recursos) es una forma de decirle al navegador; “Este recurso en específico podrías necesitarlo después”.
  • Preconnect (dominios) nos ayuda a solucionar el handshacking de HTTP que sucede entre el navegador y los servidores de forma anticipada.

Next.js usa mucho preload, hace un muy buen trabajo diviendo el bundle de JS en partes muy pequeñas. Esta técnica se conoce como code spliting.

Para los que estén haciendo el curso después del sep 2021, pueden ver el efecto del preload en el footer, en more y general resources, ya que en el nav al menos a mi no me precargaba las cosas como al profe

El crossOrigin que quiere decir?

Excelente!!

todo esto está bien pero en la práctica aplicado a un wordpress y mucho más difícil

Por si alguien mas quedó con la duda de que es http handshaking:

https://www.cloudflare.com/learning/ssl/what-happens-in-a-tls-handshake/

Estrategias

  • Preload (recursos)
  • Prefetch (recursos)
  • Preconnect (dominios)
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin />
<link rel="dns-prefetch" href="https://fonts.gstatic.com/" />

<link rel="preconnect" href="https://kitsu.io/" crossorigin />
<link rel="dns-prefetch" href="https://kitsu.io/" />

“DNS-prefetch es un intento de resolver los nombres de dominio antes de que se soliciten los recursos. Esto podría ser un archivo cargado más tarde o un destino de enlace que un usuario intenta seguir…”

Documentacion

Luego de aplicar el prefetch y el preconnect a nuestro codigo, como podemos “ver” el impacto que tiene esos cambios en el rendimiento de nuestra aplicacion?

y cómo aplicar estos recursos en frameworks, por ejemplo, en reacts?? Gracias por su ayuda.

jajaja este plugin de dark mode esta haceindo cosas locas miren estos estilos que me aparecieron en esta clase