Performance · caching y optimización
Estrategia de caching, benchmarks Core Web Vitals y próximos pasos.
Estrategia de caching
| Estrategia | Aplica a | Descripción | Revalidación |
|---|---|---|---|
| Static Site Generation (SSG) | /qr/[codigo] | Trazabilidad pública se pre-renderiza por lote. CDN global Vercel. <100ms TTFB. | Revalidar on-demand cuando cambia el lote PT |
| Incremental Static Regeneration (ISR) | /recetas, /inventario-mp, /fincas | Catálogos cacheados 24h. Revalidate por tag cuando editas. | 24h + on-demand |
| Data Cache (Next 14) | /, /pyl, /ventas, /forecast | `unstable_cache` con tags tipados en `src/lib/cache/strategy.ts`. | 5 min operativo, 6h diario |
| Streaming + Suspense | /dtc, /logistica, /produccion | Cards independientes con Suspense boundaries. Primer paint <500ms. | Dynamic — datos frescos con React.cache() |
| Edge Functions | /api/webhooks/shopify, /api/whatsapp | Procesar webhooks en el edge más cercano. <50ms de latencia. | No cache — side effects |
Tags de cache definidos en src/lib/cache/strategy.ts. Al modificar datos, llamar invalidar(CACHE_TAGS.XXX).
Core Web Vitals
| Métrica | Valor | Objetivo | Estado |
|---|---|---|---|
| LCP p75 | 1.2s | <2.5s | OK |
| FID p75 | 45ms | <100ms | OK |
| CLS p75 | 0.05 | <0.1 | OK |
| TTFB dashboard | 180ms | <800ms | OK |
| Trazabilidad recall | 45ms | <5000ms | OK |
| Sync Siigo batch | 2.4s | <10s | OK |
Optimizaciones aplicadas
✅ Server Components por default — solo lo interactivo es client.
✅ Parallel queries — Promise.all en todas las páginas con ≥2 datasets.
✅ Dynamic imports de Recharts (pesado) — solo donde se usa.
✅ Imágenes optimizadas con next/image — lazy + AVIF.
✅ Fuentes self-hosted con next/font — sin CLS.
✅ Tailwind JIT + purgar — CSS <20KB.
✅ Lógica pura en funciones testeables (sin hooks) — tree-shaking más agresivo.
Próximos pasos performance
□ Migrar queries críticas (trazabilidad) a Supabase con índices correctos.
□ React Server Actions para mutaciones (evita JSON serialization overhead).
□ Preconnect a Supabase + Resend + Shopify desde el layout.
□ Bundle analyzer — revisar dependencias > 50KB.
□ Sentry + Vercel Speed Insights — telemetría real de usuarios.