A lightweight jQuery Plugin for Server-Sent Events (SSE) EventSource Polyfill. This plugin tries to use the native EventSource object if it's supported by the browser. If there is no native support, the request is made by Ajax requests (polling). You do not need to change the server side nor the client side.
If you are looking for an SSE Polyfill library without jQuery dependency try yaj-sse. The yaj-sse is a port from version 0.1.4 of jQuery SSE.
var sse = $.SSE('http://example.com/sse-server.php', {
onMessage: function(e){
console.log("Message"); console.log(e);
}
});
sse.start();echo "data: My Message\n";
echo "\n";For comprehensive documentation, please refer to the following guides:
- Getting Started - Installation, dependencies, and quick start guide
- Usage - Constructor, methods (start, stop), and basic usage
- Configuration - Event callbacks, options, headers, and custom events
- Examples - Code examples for common use cases and running examples locally
- Known Limitations and Quirks - Browser compatibility, Ajax fallback limitations, and debugging tips
- API Reference - Complete API documentation with all methods and properties
- References and Resources - External resources, specifications, and related projects
- Automatic detection and use of native EventSource when available
- Seamless fallback to Ajax polling when EventSource is not supported
- Support for custom events
- Custom HTTP headers support (automatically uses Ajax mode)
- Automatic reconnection with configurable retry intervals
- Event IDs and Last-Event-ID tracking
- Simple jQuery-style API
<script src="jquery.sse.min.js"></script>bower install jquery-sse<script src="https://cdn.jsdelivr.net/npm/jquery-sse@latest/jquery.sse.min.js"></script>- ✅ Chrome 6+
- ✅ Firefox 6+
- ✅ Safari 5+
- ✅ Opera 11+
- ✅ Edge 79+
- ❌ Internet Explorer (uses Ajax fallback automatically)
Contributions are welcome! Please feel free to submit pull requests or open issues on GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.