Performance: Relative vs absolute URL resolution
MEDIUM IMPACT
This concept affects how URLs are resolved in web requests, impacting network request efficiency and caching behavior.
const baseUrl = 'https://example.com/assets/'; const imageUrl = new URL('data.json', baseUrl).href; fetch(imageUrl).then(res => res.json());
const imageUrl = 'https://example.com/assets/data.json';
fetch(imageUrl).then(res => res.json());| Pattern | DNS Lookups | Cache Efficiency | Network Overhead | Verdict |
|---|---|---|---|---|
| Absolute URL | Multiple per resource | Lower due to domain changes | Higher due to repeated lookups | [X] Bad |
| Relative URL | Single or none | Higher due to consistent domain | Lower network overhead | [OK] Good |