defer loading of persona include.js (bug 983556)#398
defer loading of persona include.js (bug 983556)#398cvan wants to merge 1 commit intomozilla:masterfrom cvan:potatopersona
Conversation
There was a problem hiding this comment.
I'll need to update this in zamboni's mkt.commonplace template of course
There was a problem hiding this comment.
Maybe not a huge deal, but nothing is telling you that the setInterval actually waited for persona_step ms and not more. If you want to be safe, I think you need to do Date comparisons here.
Also, I am not sure you need the interval to be as low as 25ms.
There was a problem hiding this comment.
well, it's going to be at most 24ms off.
There was a problem hiding this comment.
It can be much much worse. Browsers don't respect setInterval/setTimeout when you are not the foreground tab, not to mention possible delays because other processes want the CPU for themselves.
If you want to test, open a tab with http://virgule.net/tmp/test-interval.html, quickly open another tab and start doing something in that tab for a few seconds, come back and look at your js console ; you should see that some iterations took up to 1 second instead of 25 ms.
There was a problem hiding this comment.
good call, will change
There was a problem hiding this comment.
I wanted to keep it as low as possible
Notice we already doing But, yeah... |
|
💚 the build passed! Travis is a doggone liar! |
When the page first loads, and if the user was not already signed in, we set
cursor: waitfor the "Sign in" link so it's clear that the user is in some holding pattern. (I haven't been able to see this, even on my crappy Comcast connection, unless I'm proxying Persona through a delayer.)We check if Persona has been loaded every 25 milliseconds (simple
'id' in navigatorcheck).a. If Persona loads within the 30 seconds, we resolve the deferred and let the user sign in (i.e., we call
navigator.id.watch).b. If Persona times out after 30 seconds, we reject the deferred and pop up a notification telling the user that Persona is responsive.
Feel free to test this locally with http://deelay.me/5000/http://login.persona.org/include.js to simulate a slow Persona load.