# optimole-wp/4.2.9/assets/js/modules/device.js

Optimole – Optimize Images | Convert WebP &amp; AVIF | CDN &amp; Lazy Load | Image Optimization, version 4.2.9. 58 lines.

- Page: https://pluginprobe.com/plugins/optimole-wp/4.2.9/code/assets/js/modules/device.js
- Raw: https://pluginprobe.com/plugins/optimole-wp/4.2.9/raw/assets/js/modules/device.js
- Modified: 2025-10-09T13:04:24+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/optimole-wp/4.2.9/code/assets/js/modules/device.js#L10-L20`.

```javascript
/**
 * Optimole Device Detection Module
 * Handles device type detection based on screen width
 */

import { optmlLogger } from './logger.js';

/**
 * Device detection utilities
 */
export const optmlDevice = {
    /**
     * Device type constants
     */
    DEVICE_TYPES: {
      MOBILE: 1,
      DESKTOP: 2
    },

    /**
     * Screen width threshold for mobile/desktop detection
     * This is similar to what PageSpeed Insights uses
     */
    MOBILE_BREAKPOINT: 600,

    /**
     * Determine device type based on screen width
     * @returns {number} Device type (1=mobile, 2=desktop)
     */
    getDeviceType: function() {
      const width = window.innerWidth;
      
      if (width <= this.MOBILE_BREAKPOINT) {
      optmlLogger.info('Device detected as mobile based on width:', width);
        return this.DEVICE_TYPES.MOBILE;
      }
      
      optmlLogger.info('Device detected as desktop based on width:', width);
      return this.DEVICE_TYPES.DESKTOP;
    },

    /**
     * Check if current device is mobile
     * @returns {boolean} True if mobile device
     */
    isMobile: function() {
      return this.getDeviceType() === this.DEVICE_TYPES.MOBILE;
    },

    /**
     * Check if current device is desktop
     * @returns {boolean} True if desktop device
     */
    isDesktop: function() {
      return this.getDeviceType() === this.DEVICE_TYPES.DESKTOP;
    }
};

```
