Я заметил, что после добавления одного SSE моя страница обновлялась дольше (иногда до 30 секунд, для меня это категорический запрет). Пока страница пыталась перезагрузиться, я заметил, что SSE
Код: Выделить всё
onmessage
Код: Выделить всё
function new_event() {
if (typeof(EventSource !== undefined)) {
var ES = new EventSource('../folder/file.php');
/** This event continues while page tries to refresh **/
ES.onmessage = function(ev) {
var data = ev.data;
// Data is still outputed in the console while page tries to refresh
console.log(data);
}
}
I tried adding an
Код: Выделить всё
onunload
Код: Выделить всё
var ES = new EventSource('../folder/file.php');
window.onunload = function(){
ES.close();
}
Why does the Event Source persist while the page tries to reload? Is this a back-end problem since the bulk of the work is done on the back-end? Why didn't the
Код: Выделить всё
onunload
Note that this same problem occurs when I try to navigate away from the page.
Is there a way to close the Event Source connection without lagging the page on page refresh?
Источник: https://stackoverflow.com/questions/610 ... age-reload