🚀
Adaptive loading helper Helper util to get info about the target platform performance
Use Cases
-
Battery
🔋 // If the device is currently charging // Or the battery level is more than 20% if (adaptiveData.battery.charging || adaptiveData.battery.level > 0.2) { await import('./costly-module.js'); }
-
CPU
💻 if (adaptiveData.cpu > 4) { await import('./costly-module.js'); }
-
Memory
📝 if (adaptiveData.memory > 1) { await import('./costly-module.js'); }
-
Storage
💾 const fiftyMegabytesInBytes = 50 * 1e+6; if (adaptiveData.quota > fiftyMegabytesInBytes) { await import('./costly-module.js'); }
-
Network
🌐 //4g does not mean fast! if (adaptiveData.network.connection === '4g' || adaptiveData.network.downlink > 6) { await import('./costly-module.js'); }
-
Mobile
📱 if (!adaptiveData.isMobile) { await import('./costly-module.js'); }
Example
$ npm install adaptive-loading-helper
const { getAdaptiveLoadingData } = require('adaptive-loading-helper');
// ES2015 modules
import getAdaptiveLoadingData from 'adaptive-loading-helper';
const adaptiveData = await getAdaptiveLoadingData();
console.log(adaptiveData);
// {"battery": {"charging": true, "level": 3}, "cpu": 6, "memory": 8, "network": {"connection": "4g", "downlink": 6}, "quota": 50000000}