{"id":37729951,"url":"https://github.com/techiev2/deferq","last_synced_at":"2026-01-20T17:00:15.349Z","repository":{"id":330141312,"uuid":"1120713546","full_name":"techiev2/deferq","owner":"techiev2","description":"A tiny, zero-dependency JavaScript library for queuing async actions when offline and automatically retrying them when connectivity returns.","archived":false,"fork":false,"pushed_at":"2025-12-23T18:53:19.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-12-25T02:34:39.034Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techiev2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-21T19:41:56.000Z","updated_at":"2025-12-23T18:53:23.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/techiev2/deferq","commit_stats":null,"previous_names":["techiev2/deferq"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/techiev2/deferq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techiev2%2Fdeferq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techiev2%2Fdeferq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techiev2%2Fdeferq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techiev2%2Fdeferq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techiev2","download_url":"https://codeload.github.com/techiev2/deferq/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techiev2%2Fdeferq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-16T13:48:35.751Z","updated_at":"2026-01-20T17:00:15.332Z","avatar_url":"https://github.com/techiev2.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deferq\n\nA tiny, zero-dependency JavaScript library for queuing async actions when offline and automatically retrying them when connectivity returns.\n\n- **Lightweight**: ~30 lines of code\n- **Zero dependencies**\n- **Concurrent retries**: All queued actions run in parallel when back online\n- **Flexible**: Queue any async function by name\n\nIdeal for simple offline support without the complexity of service workers.\n\n## Installation\n\n### Via npm\n\nInstall with: `npm install deferq`\n\n### Via CDN\n\n```html\n\u003cscript src=\"https://app.unpkg.com/deferq@1.1.3/files/index.js\"\u003e\u003c/script\u003e\n```\n\n\n## Usage\n### 1. Initialize the library (once)\n```JavaScript\n\u003cscript type=\"module\"\u003e\n  import { addToQueue, register } from 'https://cdn.jsdelivr.net/npm/deferq@1.1.3/index.js'; // Automatically registers the \"online\" listener\n\u003c/script\u003e\n```\n\n### 2. Queue actions when offline\n```JavaScript\nasync function createPost({ post }) {\n  if (!navigator.onLine) {\n    addToQueue('networkQueue', 'createPost' { post });\n    showToast(\"Offline — we'll retry when you're back online.\", 5);\n    return;\n  }\n\n  const res = await fetch('/api/post', {\n    method: 'POST',\n    body: JSON.stringify({ post }),\n    headers: { 'Content-Type': 'application/json' }\n  });\n  // handle response...\n}\n\n// Call your function as usual\ncreatePost({ post: \"Hello world!\" });\n```\n\n### 3. Automatic retry\nWhen the browser fires the \"online\" event, deferq:\n\n- Loads the queue from internal storage.\n- Executes all queued functions serially to avoid a thundering herd.\n- Removes successful actions.\n- Keeps persistent failures for the next online event.\n\nNo additional setup required.\n\n## API\n```JavaScript\naddToQueue(key: string, fnName: string, payload: any)\n````\nQueues an action.\n\n- key: key for the queue (e.g., 'networkQueue', 'fetchQueue', 'transferQueue')\n- fnName: Name of the function as it was registered to deferq.\n- payload: Data to pass to the function when replayed\n\nExample: addToQueue('networkQueue', 'createPost', { post: 'data' })\n\n\n## How It Works\n\n- When offline, use addToQueue instead of calling the function directly.\n- Actions are cached in internal storage under the given key.\n- On \"online\", deferq replays all actions serially.\n- Successful actions are removed; failed ones remain for future retries.\n\n## Notes\n\n- In v1.1.3, actions are no longer stored in localStorage to avoid pollution and XSS attacks.\n- Functions to queue must be pure functions and not use global state, for safety and proper application.\n- No built-in queue size limit (add your own in production if needed).\n- Works in all modern browsers.\n\n### Function Naming Requirement\n\nFor automatic retry to work, the calling function must have a name that appears in the stack trace.\n\nWorks:\n- Named function declarations: `function createPost() {}`\n- Named function expressions: `const post = function createPost() {}`\n\nDoes not work:\n- Arrow functions: `const createPost = async () =\u003e {}`\n- Anonymous functions\n\n*Recommendation*: Use named functions for actions that may be queued offline.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechiev2%2Fdeferq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechiev2%2Fdeferq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechiev2%2Fdeferq/lists"}