Fix for async loading of TTVC lib#91
Conversation
|
|
ajhyndman
left a comment
There was a problem hiding this comment.
Thanks for contributing this fix back!
The test looks good and I have verified your solution works. Please sign the CLA so that we can accept your pull request.
Heads up, I also just fixed a lint failure in master, so it may be helpful for you to rebase to resolve that here.
|
Also, for the record, and in case anyone else stumbles on this issue: we strongly recommend loading the ttvc library synchronously and as early in the document as possible to ensure accurate stats are reported. |
|
@ajhyndman sorry, let me go through the steps to be able to contribute to it here from my work account I and will re-do the submission. |
|
Closed in favor of #92 |
This PR addresses the issue where ttvc is loaded into an SPA after the window.load has fired.
In the current state that means the observer for the resources never registers.
This is already properly handled in the
waitForPageLoadcalled fromvisuallyCompleteCalculator, we check thedocument.readyStateand immediately resolve if it is complete. But it was not handled for the networkIdleObservable.I have added the test that validates this behavior. Without the fix it marks ttvc before the img is ever downloaded.
Obviously there is still a gap if the resource started downloading before ttvc was initialized, but at least this way ttvc will work for future SPA navigations. Without this fix any future resources (e.g. additional bundles) are also not tracked.