4 ms·
How do you detect whether the user's browser has a slow implementation of an API without actually freezing the browser for 8 seconds?
by madeofpalk 4y ago
How do you detect whether the user's browser has a slow implementation of an API without actually freezing the browser for 8 seconds?
- vlovich123 4y ago1. Pick the API that's most likely to be the fastest (based on marketshare) as the default to use. 2. Use `setInterval` to start your benchmark routine. 3. Benchmark function runs the API using a simple loop that will return quickly (i.e. within 2ms) using performance.now to evaluate. 4. When you obtain enough samples to indicate an alternate path is faster disable the benchmark function No freezing the browser. Shouldn't take too long to switch to an optimized version. That being said, this is a lot of complexity / hard to implement in a robust and fast way so I'm not saying it's a better answer.
- madeofpalk 4y agoYeah or just test the user agent.