Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XMLHttpRequest on main thread is deprecated #71

Open
Jos512 opened this issue May 5, 2019 · 2 comments
Open

XMLHttpRequest on main thread is deprecated #71

Jos512 opened this issue May 5, 2019 · 2 comments
Labels

Comments

@Jos512
Copy link

Jos512 commented May 5, 2019

If I perform a Google mobile friendly test on a website that uses ga-lite, I get the following error message:

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/

Here's an example of such a mobile friendliness report.

The problem looks to be caused by this line.

@jehna
Copy link
Owner

jehna commented May 6, 2019

Hmm. This tracks down to the very first commit:

ga-lite/src/ga-lite.js

Lines 21 to 22 in 719d3c7

req.open('GET', url, false);
req.send();

Back then ga-lite had functionality of sending the pageviews on window.onunload, and since Internet Explorer doesn't support navigator.sendBeacon, there was a fallback to use XMLHttpRequest. The gist here is that IE needed to use synchronous requests to guarantee taht those requests were finished on the unload event.

This means we can safely remove the synchronous flag from the XMLHttpRequest call.

@jehna jehna added the bug label May 6, 2019
@jehna
Copy link
Owner

jehna commented May 6, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants