Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
10-Jul-2025To detect stale data in IndexedDB during synchronization with a remote server, the most common and reliable technique is to use timestamps or versioning metadata on each record. Here’s how to handle it effectively:
1. Add a
lastModifiedorversionField per RecordEvery record stored in IndexedDB and on the server should include one of:
lastModified: A UTC timestamp (e.g., ISO 8601 or Unix Epoch).version: A monotonically increasing number (e.g.,intorUUID/ETag).Example Record:
2. Compare Timestamps during Sync
During sync:
lastModifiedorversion).Example (timestamp comparison):
3. Batch Versioning for Sync Tokens
If you want to track updates more efficiently:
lastModified > lastSyncTimestamp.lastSyncTimestamp.4. Handle Clock Skew (if using timestamps)
5. Optional: Use Hashing for Change Detection
For large documents:
Dexie.js Example
Summary
lastModifiedversionsyncStatuspending,synced,conflict)