seriousdev
seriousdev

Reputation: 7656

Is the load time worth the execution time?

Edit: Please consider the whole problem instead of focusing on the example too much.

First, let me define (1) the load time, which is the HTTP request timing from blocking to receiving and (2) the execution time, which represents the time to parse the response, compile JavaScript, etc.

For example, consider these two CSS selectors: #a and div. Obviously, the first one will resolve faster. Knowing that, I would use this selector in my CSS.

Now, if I had many more elements matching these selectors, say 10,000, and a way longer ID, say LongIdIsLongVeryLong, the page would surely load slower. But what would be the primary cause: all the <div id=LongIdIsLongVeryLong></div> instead of <div></div> (i.e. the load time), or the fact that the browser would have to apply styling to way more elements (i.e. the execution time)?

Also, why? Because the information travels faster in your computer than through the Internet? I really don't know.

Of course, this also apply to JavaScript, etc.

I hope I've been clear and I hope you're open-minded.

Upvotes: 4

Views: 172

Answers (2)

Ivo Wetzel
Ivo Wetzel

Reputation: 46756

Completely depends on your target platforms.

On Desktop you might go along pretty well with bigger sites and nicer (not necessarily faster) code. But in the case of mobile as a main audience, reducing the size and especially the number of HTTP requests is first priority, you normally have a lot more CPU resources on such devices than you have bandwidth available.

There's really no general advice, as it depends on what kind of website / application you're building and how long people will stay on a page after it has loaded.

Upvotes: 2

Sean McMillan
Sean McMillan

Reputation: 10093

Network time will dominate processing time on nearly any machine. Especially if you're comparing two css selectors of one term each.

I'm sure you could use a mountain of javascript, or deeply nested selectors to make the processing time notable, but it's practically instant compared to the network.

Upvotes: 3

Related Questions