kapouer/window-page

Add support for script defer and Page.route

kapouer opened this issue · 2 comments

When loading window-page along with some routing script:

<script defer src="window-page.js"></script>
<script defer src="router.js"></script>

(here router.js calls Page.route(fn)).

In this case, the defer attribute might make window-page route chain run before router.js has been evaluated, thus ignoring the router promise that is set up by router.js.

It seems waitReady resolves before all deferred scripts are done, (very easy to reproduce with uncached resources at least on chrome 69).

The bug in window-page is that DOMContentLoaded is specified to be emitted after scripts (included deferred ones) are loaded, but cross-browser support in window-page:

if (document.readyState == "complete" ||
		(document.readyState != "loading" && !document.documentElement.doScroll)) {

evaluates to true because document.readyState is interactive as soon as DOM is fully parsed.

Ok this is also jquery/jquery#3271