Performance: Building URLs programmatically
MEDIUM IMPACT
This affects page load speed by controlling how URLs are constructed and used for resource fetching, impacting network requests and caching.
const url = new URL(baseUrl); url.searchParams.set('user', userId); url.searchParams.set('token', token); url.searchParams.set('page', pageNumber); const finalUrl = url.toString();
const url = baseUrl + '?user=' + userId + '&token=' + token + '&page=' + pageNumber;
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual string concatenation for URLs | 0 | 0 | 0 | [!] OK but error-prone and CPU costly |
| Using URL and URLSearchParams APIs | 0 | 0 | 0 | [OK] Efficient and reliable |