agentleFS
BuilderCedBuilderCed/agent-skills/skills/offline/offline-first-development/SKILL.md

offline-first-development

Skill2 starsChanged 7 months agoMITView on GitHub

Build offline-capable applications with IndexedDB, service workers, background sync, and conflict resolution patterns.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Does not implement a specific sync protocol (CRDT, OT)

    line 133
  2. Distinctive:

    Does not handle real-time collaboration (use dedicated tools)

    line 134
  3. Distinctive:

    Does not manage authentication tokens offline (security concern)

    line 135
  4. Distinctive:

    Does not provide a database library (guides architecture choices)

    line 136

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Offline-First Development

When to Use

  • Building apps for low-connectivity environments (rural, Africa, transit)
  • Building PWAs that must work without internet
  • Designing sync strategies for mobile apps
  • Implementing local-first architectures
  • Building for environments with unreliable connections

Core Principles

  1. Local-first: Data lives on the device. Server is backup, not source of truth.
  2. Sync on reconnect: Queue changes offline, sync when connection returns.
  3. Conflict resolution: Define merge strategy before building.
  4. Progressive enhancement: App works offline; online adds features.

Storage Options

StorageSize LimitPersistenceBest For
IndexedDB~50% of diskPersistentStructured data, large datasets
Cache API~50% of diskPersistentHTTP responses, assets
localStorage5-10 MBPersistentSmall key-value config
OPFS~50% of diskPersistentFile-like access (new)

Recommendation: IndexedDB for data, Cache API for assets, OPFS for files.

Service Worker Pattern

Install → Cache essential assets (app shell, fonts, icons)
Activate → Clean old caches
Fetch → Cache-first for assets, network-first for API data
Sync → Background sync for queued mutations

Caching Strategies

StrategyWhenHow
Cache-firstStatic assets (CSS, JS, images)Serve from cache, update in background
Network-firstAPI dataTry network, fall back to cache
Stale-while-revalidateSemi-static (user profile)Serve cache, update from network
Network-onlyReal-time data (chat, payments)No caching

Sync Patterns

Optimistic Updates

  1. Apply change locally immediately
  2. Queue mutation for sync
  3. On reconnect: send queued mutations
  4. On conflict: apply resolution strategy

Conflict Resolution Strategies

StrategyWhenHow
Last-write-winsSimple data, single userTimestamp comparison
Server-winsAuthoritative serverDiscard local on conflict
Client-winsUser autonomy priorityOverwrite server
MergeCollaborative editingField-level merge
ManualCritical dataShow conflict to user

Queue Design

Mutation queue entry:
{
  id: "uuid",
  timestamp: "ISO-8601",
  entity: "task",
  entity_id: "uuid",
  action: "create|update|delete",
  payload: { ... },
  retries: 0,
  status: "pending|syncing|failed|synced"
}

Connectivity Detection

// Basic
navigator.onLine // boolean (unreliable alone)

// Robust: combine with actual fetch test
async function isOnline() {
  try {
    const response = await fetch('/api/health', {
      method: 'HEAD',
      cache: 'no-store',
      signal: AbortSignal.timeout(3000)
    });
    return response.ok;
  } catch {
    return false;
  }
}

Mobile-Specific Considerations

  • Battery: Batch sync operations, avoid polling
  • Bandwidth: Compress payloads, delta sync
  • Storage quotas: Monitor usage, evict old data
  • App lifecycle: Handle background/foreground transitions

What This Skill Does NOT Do

  • Does not implement a specific sync protocol (CRDT, OT)
  • Does not handle real-time collaboration (use dedicated tools)
  • Does not manage authentication tokens offline (security concern)
  • Does not provide a database library (guides architecture choices)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.