Performance: Response helpers (json, error)
MEDIUM IMPACT
This affects how quickly the server sends responses and how efficiently the browser processes them, impacting page load and interaction speed.
import { json } from '@sveltejs/kit'; export async function GET() { return json({ message: 'Hello' }); }
export async function GET() { const data = { message: 'Hello' }; return new Response(JSON.stringify(data), { headers: { 'Content-Type': 'application/json' } }); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual JSON.stringify and Response | N/A | 0 | Minimal | [!] OK |
| Using json() helper from SvelteKit | N/A | 0 | Minimal | [OK] Good |
| Manual error Response with plain text | N/A | Possible extra client reflows if UI shifts | Medium if layout shifts | [X] Bad |
| Using error() helper from SvelteKit | N/A | 0 | Minimal | [OK] Good |