Page load optimization in No-Code - Time & Space Complexity
When we optimize page load, we want to know how the time to show a page changes as the page gets bigger or more complex.
We ask: How does adding more images, scripts, or content affect the loading time?
Analyze the time complexity of loading a web page with multiple resources.
loadPage(resources) {
for each resource in resources {
fetch(resource);
render(resource);
}
}
This code loads each resource one by one and then shows it on the page.
Look for repeated actions that take time.
- Primary operation: Fetching and rendering each resource.
- How many times: Once for every resource on the page.
As you add more resources, the total load time grows roughly in direct proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 fetch and render steps |
| 100 | 100 fetch and render steps |
| 1000 | 1000 fetch and render steps |
Pattern observation: Doubling the number of resources roughly doubles the load time.
Time Complexity: O(n)
This means the load time grows in a straight line as you add more resources.
[X] Wrong: "Loading more images won't affect page load time much because they load in the background."
[OK] Correct: Each image still needs to be fetched and rendered, so more images add more work and increase load time.
Understanding how page load time grows helps you design faster websites and shows you can think about real user experience.
"What if we loaded all resources at the same time instead of one by one? How would the time complexity change?"