Blog » Library Improvements and Best Practices

We have implemented some improvements for our JavaScript API and the Simple UI to help you deliver a better experience for your users.

The JavaScript API has gained two new methods: miner.isMobile() to check if the user is on a phone or tablet and miner.didOptOut() to check if the user did cancel the opt-in screen in the last few hours.

Mining on mobile devices is quite slow and it also drains the battery quickly. So to be more user friendly, consider to disable mining on mobile devices completely. Also, if the user cancels the opt in, you probably don't need to show it again on each new page load. You can achive both now with a simple if:

// Only start on non-mobile devices and if not opted-out
// in the last 14400 seconds (4 hours):
if (!miner.isMobile() && !miner.didOptOut(14400)) {
	miner.start();
}

For the Simple UI you can now listen on all miner events, just like for the JavaScript API. See the documentation for the details.

posted on Nov 01, 2017, the Coinhive Team

© 2017 coinhive