PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.8
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.8
4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 3.11.3 3.12.0 3.12.1 All 134 releases
optimole-wp / assets / js / modules / device.js

device.js in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 4.2.8, at assets/js/modules/device.js

58 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Optimole Device Detection Module
3 * Handles device type detection based on screen width
4 */
5
6 import { optmlLogger } from './logger.js';
7
8 /**
9 * Device detection utilities
10 */
11 export const optmlDevice = {
12 /**
13 * Device type constants
14 */
15 DEVICE_TYPES: {
16 MOBILE: 1,
17 DESKTOP: 2
18 },
19
20 /**
21 * Screen width threshold for mobile/desktop detection
22 * This is similar to what PageSpeed Insights uses
23 */
24 MOBILE_BREAKPOINT: 600,
25
26 /**
27 * Determine device type based on screen width
28 * @returns {number} Device type (1=mobile, 2=desktop)
29 */
30 getDeviceType: function() {
31 const width = window.innerWidth;
32
33 if (width <= this.MOBILE_BREAKPOINT) {
34 optmlLogger.info('Device detected as mobile based on width:', width);
35 return this.DEVICE_TYPES.MOBILE;
36 }
37
38 optmlLogger.info('Device detected as desktop based on width:', width);
39 return this.DEVICE_TYPES.DESKTOP;
40 },
41
42 /**
43 * Check if current device is mobile
44 * @returns {boolean} True if mobile device
45 */
46 isMobile: function() {
47 return this.getDeviceType() === this.DEVICE_TYPES.MOBILE;
48 },
49
50 /**
51 * Check if current device is desktop
52 * @returns {boolean} True if desktop device
53 */
54 isDesktop: function() {
55 return this.getDeviceType() === this.DEVICE_TYPES.DESKTOP;
56 }
57 };
58