I Built an Offline-First HTTP Request Queue for Angular
GitHub Have you ever had a user submit a form, lose their internet connection, and watch their request fail? I wanted to solve this problem in Angular without forcing developers to build their own queue, IndexedDB storage, retry logic, and network synchronization. So I built ngx-offline-sync — an open-source Angular library for offline-first HTTP request synchronization. How it works When the…
When building Angular applications, developers often face the challenge of handling user submissions when internet connectivity is lost. An open-source Angular library called ngx-offline-sync was created to address this issue without the need for developers to build their own queue, storage, retry logic, or network synchronization.
The library operates by persisting HTTP requests locally in IndexedDB when the application is offline, rather than losing them. Once the connection is re-established, the requests are then synchronized with the server, completing the process.
Currently, ngx-offline-sync supports the automatic queuing of POST, PUT, PATCH, and DELETE requests. It uses IndexedDB for persistence and automatically synchronizes once a connection is restored. The library also handles retry logic and tracks the status of requests. Processing of requests in parallel is possible with a batchSize configuration, and integration with Angular HTTP interceptor is seamless.
To use the library, developers only need to provide the batchSize configuration option when initializing offline sync, no additional dependencies are required, and the library continues to allow the use of Angular's HttpClient as usual.
The project is still in development, with ongoing work on improving the API, documentation, testing, and network-state handling. Developers working with Angular and building applications where network interruptions are a possibility are encouraged to explore this library.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.