Live data from Hacker News

Show HN: Speed up your site by running JavaScript when the browser is idle

npmjs.com

51–60 of 95 posts

Re: Show HN: Speed up your site by running JavaScript when the browser is idle

#51
post #39
post #34

Earlier quoted context omitted.

What kind of question is that? Games or applications like Figma obviously require more computing power than a static homepage.

Do they? To do what when the computer is idle ? Those are interactive applications, there's not that much work for them to do when you're not interacting with them.

If you do too much work at once on the main thread, the application will visibly freeze.

Say you need to call a few rest apis that trigger changes to the DOM. If the user is actively interacting with your application, doing an operation like this, say every 5 seconds, could cause momentary lag that feels bad. What if you could wait to do the update until the main thread is free?

Re: Show HN: Speed up your site by running JavaScript when the browser is idle

#52
post #39

Earlier quoted context omitted.

Do they? To do what when the computer is idle ? Those are interactive applications, there's not that much work for them to do when you're not interacting with them.

If you do too much work at once on the main thread, the application will visibly freeze. Say you need to call a few rest apis that trigger changes to the DOM. If the user is actively interacting with your application, doing an operation like this, say every 5 seconds, could cause momentary lag that feels bad. What if you could wait to do the update until the main thread is free?

Question.. is this using multiple threads?

If it isn't, how is this different than async operations?

Re: Show HN: Speed up your site by running JavaScript when the browser is idle

#53
post #39

Earlier quoted context omitted.

Do they? To do what when the computer is idle ? Those are interactive applications, there's not that much work for them to do when you're not interacting with them.

If you do too much work at once on the main thread, the application will visibly freeze. Say you need to call a few rest apis that trigger changes to the DOM. If the user is actively interacting with your application, doing an operation like this, say every 5 seconds, could cause momentary lag that feels bad. What if you could wait to do the update until the main thread is free?

Making changes to the DOM seconds later is the part I don't get. Either it's part of interaction and therefore it's urgent, or it's... what?

Re: Show HN: Speed up your site by running JavaScript when the browser is idle

#55

Earlier quoted context omitted.

If you do too much work at once on the main thread, the application will visibly freeze. Say you need to call a few rest apis that trigger changes to the DOM. If the user is actively interacting with your application, doing an operation like this, say every 5 seconds, could cause momentary lag that feels bad. What if you could wait to do the update until the main thread is free?

Question.. is this using multiple threads? If it isn't, how is this different than async operations?

It is async, the operation is delayed until the processor has nothing important to do.

Re: Show HN: Speed up your site by running JavaScript when the browser is idle

#56
post #46
post #40

Earlier quoted context omitted.

It's not about the computer being idle. It's about waiting for the main thread to be unblocked before doing stuff you would want to do anyway, but now you can schedule it for later to give priority to more urgent tasks. A very common optimization technique in all sorts of software and I don't see why it wouldn't be valid for a web application. Go read https://developer.mozilla.org/en-US/docs/Web/API/Background_... fo…

You still haven't answered the question. Your link has no example of use cases, though it has warnings about what not to do.

Can't reply above. So it's "low-priority" async?

Re: Show HN: Speed up your site by running JavaScript when the browser is idle

#58
post #6

I have an idea: why not speed up your site by NOT running js at all?

you are absolutely right. we should completely throw away the development of browser APIs over the years and develop sites with html 4.0

Incoming flood of edgelord comments saying they think that would be better

Re: Show HN: Speed up your site by running JavaScript when the browser is idle

#60
There's lots of confusion what this is. Basically browser runs a giant eventloop. Whenever you call async function in javascript, it gets put into a queue, and called by the event loop (usually the next execution). This basically makes it so that the async call gets tagged with metadata that tells the event queue "Don't call me unless you have nothing else to call". So basically it keeps the async call at the end of the queue until it's the final call, and that's when the eventloop will call it. The subject is quite misleading as it is not really about idle.
Post reply on HN