PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.6
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.6
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 / storage.js

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

61 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Optimole Storage Module
3 * Handles session storage operations for tracking processed pages
4 */
5
6 import { optmlLogger } from './logger.js';
7
8 /**
9 * Storage utilities for managing processed page data
10 */
11 export const optmlStorage = {
12 /**
13 * Generate storage key for URL and device type combination
14 * @param {string} url - Page URL or profile ID
15 * @param {number} deviceType - Device type (1=mobile, 2=desktop)
16 * @returns {string} Storage key
17 */
18 getKey: function(url, deviceType) {
19 return `optml_pp_${url}_${deviceType}`;
20 },
21
22 /**
23 * Check if a URL/device combination has been processed
24 * @param {string} url - Page URL or profile ID
25 * @param {number} deviceType - Device type (1=mobile, 2=desktop)
26 * @returns {boolean} True if already processed
27 */
28 isProcessed: function(url, deviceType) {
29 try {
30 const key = this.getKey(url, deviceType);
31 const storedValue = sessionStorage.getItem(key);
32
33 if (!storedValue) return false;
34
35 // Check if the stored timestamp is still valid (within current session)
36 const timestamp = parseInt(storedValue, 10);
37 const now = Date.now();
38
39 // Consider it valid if it exists in the current session
40 return true;
41 } catch (e) {
42 optmlLogger.error('Error checking sessionStorage:', e);
43 return false;
44 }
45 },
46
47 /**
48 * Mark a URL/device combination as processed
49 * @param {string} url - Page URL or profile ID
50 * @param {number} deviceType - Device type (1=mobile, 2=desktop)
51 */
52 markProcessed: function(url, deviceType) {
53 try {
54 const key = this.getKey(url, deviceType);
55 sessionStorage.setItem(key, Date.now().toString());
56 } catch (e) {
57 optmlLogger.error('Error setting sessionStorage:', e);
58 }
59 }
60 };
61