ページが本当に読み込まれたことを確認することは、必ずしも容易ではありません。特にAjax経由でコンテンツに依存するページや、非同期に読み込まれる他のアセット(各アセットは、例えば画像のような他のアセットとは独立して並行して読み込むことができます)。このような状況に近づいへ
私の提案:
は、いくつかのグローバル繰延オブジェクト(約束)を作成し、それだけで、それが「準備完了」であるに依存しているすべてのものの後に解決されますことを確認してください。
最小例:
// start your web app code..
var p1 = new Promise();
var p2 = new Promise();
var p3 = new Promise();
// when all dependencies are done loading, means the page is truly "ready"
Promise.all([p1, p2, p3])
.then(() => {
// page done loading
});
// somewhere in the code...wait for Ajax content to load
// and resolve "p1" after the content has loaded
p1.resolve();
// somewhere in the code...wait for some other Ajax content to load
// and resolve "p2" after the content has loaded
p2.resolve();
// somewhere in the code...wait for all the images to load
// (http://stackoverflow.com/a/1977898/104380)
// and resolve "p3"
p3.resolve();
ポイントは手動で非同期完全にロードされているされているすべてのさまざまな部分を確認する必要があるということです。面倒な作業ですが、非常に堅実な解決策です。