Reputation: 25567
performing a GET in order to send data to an API before a user leaves the page can be seen as a performance issue.
Is there an alternative or a way a developer can optimize the client side javascript?
One of the great examples is: Google Analytics!
Upvotes: 1
Views: 508
Reputation: 25675
I haven't noticed too much of a hit in our applications when we bind to the beforeunload event:
$(window).bind('beforeunload', function() {
// Perform your GET
});
Not sure if Google Analytics is doing it this way though.
Upvotes: 1
Reputation: 5427
It can be difficult to perform an action before a user leaves the page. If you have to make sure you capture data w/o the user submitting it manually, you could perform AJAX operations either when the user changes any input fields, or use setTimeout to periodically collect information and send it to the server.
Upvotes: 1