Performance: Geolocation and edge logic
MEDIUM IMPACT
This affects page load speed and responsiveness by deciding where and how geolocation logic runs, impacting server response time and client rendering.
import { cookies } from 'next/headers'; export const runtime = 'edge'; export async function GET() { const cookieStore = cookies(); const userLocation = cookieStore.get('user-location'); // Use edge logic to read location from cookie or fallback return new Response(JSON.stringify({ location: userLocation?.value || 'default' })); } // Client fetches precomputed location from edge API
'use client'; import { useState, useEffect } from 'react'; export default function Page() { const [location, setLocation] = useState(null); useEffect(() => { navigator.geolocation.getCurrentPosition(pos => { setLocation(pos.coords); }); }, []); return <div>{location ? `Lat: ${location.latitude}` : 'Loading...'}</div>; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side geolocation after load | Minimal DOM changes | 1 reflow after location set | Delays initial paint | [X] Bad |
| Edge runtime geolocation or precomputed location | No extra DOM operations | No reflows caused by location fetch | Faster initial paint | [OK] Good |