This is why fetch or setTimeout don't block the render
Jake Archibald - "In the Loop"
while (true) {
console.log('To infinity and beyond!');
}
// Will never run!
extremelyImportantFunction();
Smooth animation means painting 60 frames per second
Browser takes ~4 ms per frame to do work
All of our JS for each frame has to take ~12 ms or less
Run scripts in separate background thread, so that we don't block the main thread
When to use Web Workers:
Web Workers API docs:
https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API
Comlink (awesome Web Workers library):
https://github.com/GoogleChromeLabs/comlink
react-app-rewired:
https://github.com/timarney/react-app-rewired
worker-loader:
Questions? Ask me here or on Twitter!