Performance: Absolute vs relative URLs
This concept affects page load speed by influencing how quickly the browser can resolve and fetch resources.
<img src="/images/photo.jpg" alt="Photo">
<img src="https://www.example.com/images/photo.jpg" alt="Photo">
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Absolute URL for internal resource | No extra DOM nodes | 0 | Minimal | [✗] Bad |
| Relative URL for internal resource | No extra DOM nodes | 0 | Minimal | [✓] Good |
absolute URL?https://example.com/page shows a full address with protocol and domain, matching the absolute URL definition.style.css in the same folder?style.css uses just style.css, which correctly points to the file in the same folder.https://example.com/blog/post1.html, what will the browser load for the relative URL ../images/pic.jpg?.. in relative URLs.. means go up one folder from the current page location./blog/. Going up one folder leads to /. Then adding images/pic.jpg gives /images/pic.jpg... moves up one folder [OK].. means go up one folder in URL path [OK].. stays in the same folder<a href="images/photo.jpg">Photo</a> on the page https://example.com/about/index.html, but the image does not load. What is the likely problem?images/photo.jpg looks for an images folder inside the current folder /about/.images folder is not inside /about/, the link will break. This is the likely cause.https://example.com/products/item.html. Which URL should you use to ensure the link works correctly regardless of the current page location?Pass the test and this pattern moves unknown