diff --git a/src/routes/_utils/isMobile.js b/src/routes/_utils/isMobile.js deleted file mode 100644 index b272a337..00000000 --- a/src/routes/_utils/isMobile.js +++ /dev/null @@ -1,11 +0,0 @@ -// Rough guess at whether this is a "mobile" device or not, for the purposes -// of "device class" estimations - -let cached - -export function isMobile () { - if (typeof cached === 'undefined') { - cached = !!(process.browser && navigator.userAgent.match(/(iPhone|iPod|iPad|Android)/)) - } - return cached -} diff --git a/src/routes/_utils/runMediumPriorityTask.js b/src/routes/_utils/runMediumPriorityTask.js index 9696b396..5e489af1 100644 --- a/src/routes/_utils/runMediumPriorityTask.js +++ b/src/routes/_utils/runMediumPriorityTask.js @@ -1,6 +1,9 @@ import { scheduleIdleTask } from './scheduleIdleTask' import { store } from '../_store/store' -import { isMobile } from './isMobile' + +// Rough guess at whether this is a "mobile" device or not, for the purposes +// of "device class" estimations +const IS_MOBILE = process.browser && navigator.userAgent.match(/(?:iPhone|iPod|iPad|Android)/) // Run a task that doesn't need to be processed immediately, but should // probably be delayed if we're on a mobile device. Also run it sooner @@ -8,7 +11,7 @@ import { isMobile } from './isMobile' export function runMediumPriorityTask (fn) { if (store.get().pageVisibilityHidden) { fn() - } else if (isMobile()) { + } else if (IS_MOBILE) { scheduleIdleTask(fn) } else { requestAnimationFrame(fn)