JavaScript: How to determine performance of the runtime (aka browser)?

对着背影说爱祢 提交于 2021-01-28 03:31:08

问题


I have a JavaScript application, which works fine, but certainly needs some memory / CPU performance (it is based on top of Google maps).

So basically it runs fine on a Desktop / Laptop PC, iPad works OK. But with all these different devices nowadays, smaller devices are definitely overloaded.

So basically I want to determine the available runtime and decide whether I start my JavaScript application, or display a message instead.

  1. OK, I could check the browser, but this is a never ending story
  2. I could check on the OS information, but again this is very tedious. Also some OS run on high performance devices as well as low end hardware.
  3. I could check on the screen size and rule out mobile phones, but then it gets difficult

So is there a way to determine the performance of the client? Just to make it clear, I do not care whether it is a tablet for instance, but if it is a low performance tablet with little CPU performance / memory (so Detect phone/tablet/web client using javascript does not help).


回答1:


In javascript You could check list of features and based on that do conclusion if device is low memory.

For example:

  1. Check core count with window.navigator.hardwareConcurrency (For better coverage add Core Estimator polyfill)

  2. Check WebGL support (I like user2070775 suggestion): Proper way to detect WebGL support?

  3. Check if its desktop or mobile. Most likely desktop will not have any problems with memory.

  4. Check resolution of screen - most likely small resolution will be on low memory devices.



来源:https://stackoverflow.com/questions/15260403/javascript-how-to-determine-performance-of-the-runtime-aka-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!