Say Bye with JavaScript Beacon
Sometimes we want to send a piece of data to our servers when user leaves our website or webapp. Maybe it’s for for analytics or even auto-logout when they leave the website. But do you know what is a reliable way of doing it? Most of you might say use XMLHTTPRequest (or fetch) in beforeunload or unload events. Like, window . addEventListener ( "beforeunload" , () => { fetch ( '/analytics' , { method : "POST" , headers : { "Content-Type" : "application/json" , }, body : JSON . stringify ({ eve