perf: complete performance audit optimizations
This commit is contained in:
@ -3,6 +3,7 @@ import vue from '@vitejs/plugin-vue'
|
||||
import { VitePWA } from 'vite-plugin-pwa'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
import path from 'path'
|
||||
import { visualizer } from 'rollup-plugin-visualizer'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig(() => {
|
||||
@ -10,6 +11,12 @@ export default defineConfig(() => {
|
||||
plugins: [
|
||||
vue(),
|
||||
tailwindcss(),
|
||||
visualizer({
|
||||
open: false,
|
||||
filename: 'dist/stats.html',
|
||||
gzipSize: true,
|
||||
brotliSize: true
|
||||
}),
|
||||
VitePWA({
|
||||
selfDestroying: true,
|
||||
registerType: 'autoUpdate',
|
||||
@ -48,36 +55,39 @@ export default defineConfig(() => {
|
||||
navigateFallbackDenylist: [/^\/api/, /^\/rest\/v1/],
|
||||
runtimeCaching: [
|
||||
{
|
||||
// ASSETS EXTERNOS E IMÁGENES SUPERBASE
|
||||
urlPattern: /^https:\/\/(.*\.(png|jpg|jpeg|svg|webp|woff2|css))/,
|
||||
urlPattern: /^https:\/\/maps\.googleapis\.com\/.*/i,
|
||||
handler: 'CacheFirst',
|
||||
options: {
|
||||
cacheName: 'assets-estaticos-sibu',
|
||||
expiration: { maxEntries: 100, maxAgeSeconds: 60 * 60 * 24 * 30 }, // 30 días
|
||||
cacheableResponse: { statuses: [0, 200] },
|
||||
},
|
||||
cacheName: 'google-maps-cache',
|
||||
expiration: { maxEntries: 50, maxAgeSeconds: 604800 }
|
||||
}
|
||||
},
|
||||
{
|
||||
// LLAMADAS API SEMI-ESTÁTICAS (Supabase listas que no mutan tan rápido)
|
||||
urlPattern: /^https:\/\/.*\.supabase\.co\/rest\/v1\/(routes|bus_stops)/,
|
||||
urlPattern: /^https:\/\/.*\.supabase\.co\/rest\/v1\/(routes|bus_stops|businesses).*/i,
|
||||
handler: 'StaleWhileRevalidate',
|
||||
options: {
|
||||
cacheName: 'api-estatica-sibu',
|
||||
cacheableResponse: { statuses: [0, 200] },
|
||||
},
|
||||
cacheName: 'supabase-static-cache',
|
||||
expiration: { maxEntries: 30, maxAgeSeconds: 300 }
|
||||
}
|
||||
},
|
||||
{
|
||||
// LLAMADAS API REALTIME / DELUXE
|
||||
urlPattern: /^https:\/\/.*\.supabase\.co\/rest\/v1\/(shuttles|locations|users)/,
|
||||
urlPattern: /^https:\/\/.*\.supabase\.co\/rest\/v1\/.*/i,
|
||||
handler: 'NetworkFirst',
|
||||
options: {
|
||||
cacheName: 'api-dinamica',
|
||||
networkTimeoutSeconds: 5, // Vital en zonas rurales: si el 3G no responde en 5s, muestra la caché
|
||||
cacheableResponse: { statuses: [0, 200] },
|
||||
},
|
||||
cacheName: 'supabase-dynamic-cache',
|
||||
networkTimeoutSeconds: 5,
|
||||
expiration: { maxEntries: 50, maxAgeSeconds: 60 }
|
||||
}
|
||||
},
|
||||
{
|
||||
urlPattern: /^https:\/\/.*\.supabase\.co\/storage\/.*/i,
|
||||
handler: 'CacheFirst',
|
||||
options: {
|
||||
cacheName: 'supabase-images-cache',
|
||||
expiration: { maxEntries: 100, maxAgeSeconds: 2592000 }
|
||||
}
|
||||
},
|
||||
{
|
||||
// FONT CACHE (Google)
|
||||
urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\/.*/i,
|
||||
handler: 'CacheFirst',
|
||||
options: {
|
||||
@ -126,9 +136,19 @@ export default defineConfig(() => {
|
||||
if (id.includes('node_modules/@googlemaps')) {
|
||||
return 'vendor-maps'
|
||||
}
|
||||
if (id.includes('node_modules/@supabase/supabase-js')) {
|
||||
return 'vendor-supabase'
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
minify: 'terser',
|
||||
terserOptions: {
|
||||
compress: {
|
||||
drop_console: true,
|
||||
drop_debugger: true
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user