Your SvelteKit app loads like molasses and you know it. Users bail on checkout because it takes forever. Management keeps asking why the "modern" framework is slower than the old PHP site they're paying you to replace.
I spent 6 months debugging performance disasters in production SvelteKit apps. Here's the real shit that breaks performance and the fixes that actually work.
Bundle Bloat Will Murder Your App
The biggest issue? Every dependency ships to the browser. moment.js alone is 67KB. Add lodash (70KB), some crypto library (180KB+), and suddenly you're shipping 2MB+ to mobile users on 3G connections.
Server Load Functions Actually Work
Use server `load` functions instead of doing heavy lifting client-side:
// src/routes/orders/[id]/+page.server.ts
// This runs on server, not client
import moment from 'moment';
export async function load({ params }) {
const order = await getOrder(params.id);
return {
formattedDate: moment(order.date).format('MMMM Do, YYYY')
};
}
Move date formatting, crypto operations, and data transformation to the server. Ship the result, not the library. This reduces your bundle size and improves Time to Interactive for users.
Bundle Analysis Will Show You The Damage
Install rollup-plugin-visualizer to see what's killing your bundle size:
npm install --save-dev rollup-plugin-visualizer
// vite.config.js
import { visualizer } from 'rollup-plugin-visualizer';
export default {
plugins: [
sveltekit(),
visualizer({
filename: 'bundle-analysis.html',
gzipSize: true
})
]
}
Run npm run build
and open bundle-analysis.html
. The biggest blocks are your biggest problems. Usually it's date libraries, UI frameworks you're barely using, or some massive polyfill.
Bundle visualization shows exactly what's eating your bandwidth - no guesswork needed. Check Bundle Phobia before adding any new dependency to understand its impact on performance.
Windows Development is Pain
Hot reload on Windows is slower than continental drift. WSL2 helps but brings its own special hell.
Node.js v18.12.0 has a memory leak in WSL2 that kills your dev server every 2 hours. Node v18.15.0 fixed it but broke ES modules for some fucking reason. I'm running v18.14.2 which works but crashes VS Code every morning. Pick your poison.
If you're stuck on Windows:
- Use WSL2, not native Windows development
- Put your project in Linux filesystem (
/home/user/
not/mnt/c/
) - seriously, crossing filesystem boundaries kills performance - Accept that file watching will be slow and sometimes just stops working
- Install dependencies inside WSL2, not Windows - mixing package managers breaks everything
- Consider switching to Mac for development if debugging Windows file system issues costs more than the hardware
Also, Windows Defender scans every file change which makes Vite's hot reload even slower. Adding your project folder to the exclusion list helps but your security team will hate you.
Performance Monitoring That Actually Matters
Stop obsessing over Lighthouse scores and monitor real users. Core Web Vitals matter for SEO and user experience:
- LCP > 2.5s: Google ranking penalty
- FID > 100ms: Feels unresponsive
- CLS > 0.1: Layout jumps annoy users
Use web-vitals to track real performance from actual users:
npm install web-vitals
// src/app.html - track real user metrics
import { getCLS, getFID, getFCP, getLCP, getTTFB } from 'web-vitals';
getCLS(console.log);
getFID(console.log);
getFCP(console.log);
getLCP(console.log);
getTTFB(console.log);
Lighthouse CI catches performance regressions before production. Add it to your CI pipeline and it'll fail builds when performance tanks. This prevents shipping slow code to users.
That covers the theory behind performance optimization. Now let's talk about what actually works in practice. I've tested dozens of performance techniques over the years - some are game-changers, others are complete wastes of time. Here's what really moves the needle...