Performance: GET, POST, PUT, DELETE handlers
This affects how fast the app responds to user actions and updates the UI by handling data requests efficiently.
import { writable } from 'svelte/store'; const dataStore = writable([]); async function fetchData() { const response = await fetch('/api/data'); const data = await response.json(); dataStore.set(data); } // Svelte updates DOM reactively, batching changes
async function fetchData() { const response = await fetch('/api/data'); const data = await response.json(); // directly update DOM elements manually here document.getElementById('list').innerHTML = data.map(item => `<li>${item.name}</li>`).join(''); } // called on every user action without debounce or batching
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual DOM updates on every fetch | Many direct DOM changes | Multiple reflows per update | High paint cost due to full list repaint | [X] Bad |
| Using Svelte reactive stores | Minimal DOM changes via diffing | Single reflow per update | Low paint cost, only changed nodes repainted | [OK] Good |
GET handler in a route's +server.js file?export async function PUT({ request }) {
const data = await request.json();
return new Response(JSON.stringify({ updated: data.id }), { status: 200 });
}{"id": 42} in the request body?export async function DELETE(request) {
const id = await request.json().id;
return new Response(`Deleted ${id}`, { status: 200 });
}Pass the test and this pattern moves unknown