views:

38

answers:

2

Hi folks,

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!

+1  A: 

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.

dave thieben
@dave: thanks dave! Is this what Google Analytics does?
RadiantHex
not sure. I haven't used GA too much.
dave thieben
+1  A: 

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.

Pat