| sidebar_position | 1 |
|---|
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.
:::info 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. :::
- jQuery
Just download the repository and point to the jQuery plugin:
<script src="jquery.sse.js"></script>or use the minified version:
<script src="jquery.sse.min.js"></script>bower install jquery-sseYou can also use jsDelivr CDN to include the library:
<script src="https://cdn.jsdelivr.net/npm/jquery-sse@latest/jquery.sse.min.js"></script>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";