UNPKG

sse

Version:

The HTML5 Server-Sent events specification is introduced "to enable servers to push data to Web pages over HTTP or using dedicated server-push protocols".

33 lines (30 loc) 801 B
<!DOCTYPE html> <html> <head> <style> body { font-family: Tahoma, Geneva, sans-serif; } div { display: inline; } </style> <script> function updateStats(memuse) { document.querySelector('div#rss').innerText = memuse.rss; document.querySelector('div#heapTotal').innerText = memuse.heapTotal; document.querySelector('div#heapUsed').innerText = memuse.heapUsed; } var es = new EventSource("/sse"); es.onmessage = function (event) { updateStats(JSON.parse(event.data)); }; </script> </head> <body> <strong>Server Stats</strong><br> RSS: <div id='rss'></div><br> Heap total: <div id='heapTotal'></div><br> Heap used: <div id='heapUsed'></div><br> </body> </html>