Pollymer (not to be confused with Polymer, which it predates) is a general-purpose AJAX library designed for long-polling any protocol. Before you set off to write manual long-polling code again, consider using Pollymer for the task. Features include:
- Automatic retrying of failed requests, with an exponentially increasing delay between retries.
- Automatic re-polling on success, separated by a small randomized delay. Pass a function for the URL to be able to dynamically adjust the polling target.
- Workarounds for browser “busy” indications.
- JSON-P fallback for cross-domain requests on older browsers (requires server support).
Pollymer is useful for non-long-polling requests, too. For example, setting
maxTries to 2 can ensure a request survives temporary errors, much like how database drivers often try connecting twice before failing.
Code is here. The Readme should explain everything. License is MIT. Enjoy. If the library doesn’t work with your particular application protocol or flow, we’d love to hear about it.
Liked this post? Follow this blog to get more.