{"id":18814481,"url":"https://github.com/jsoon/requirejs-domready","last_synced_at":"2026-01-13T04:30:20.447Z","repository":{"id":81013088,"uuid":"54619811","full_name":"JSoon/requirejs-domReady","owner":"JSoon","description":"测试并验证requirejs domReady事件的触发时间点","archived":false,"fork":false,"pushed_at":"2016-03-24T07:46:45.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-30T00:48:31.751Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JSoon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-24T06:27:34.000Z","updated_at":"2016-03-24T07:17:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"110eddb1-3a3d-45d2-9ab7-beb27b281847","html_url":"https://github.com/JSoon/requirejs-domReady","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JSoon%2Frequirejs-domReady","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JSoon%2Frequirejs-domReady/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JSoon%2Frequirejs-domReady/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JSoon%2Frequirejs-domReady/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JSoon","download_url":"https://codeload.github.com/JSoon/requirejs-domReady/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239750270,"owners_count":19690605,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T23:41:17.116Z","updated_at":"2026-01-13T04:30:20.391Z","avatar_url":"https://github.com/JSoon.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# requirejs-domReady\n测试并验证requirejs domReady事件的触发时间点\n\n---\n\n## html\n``` html\n\u003chtml\u003e\n\n\u003chead\u003e\n    \u003ctitle\u003erequirejs domReady test\u003c/title\u003e\n\u003c/head\u003e\n\n\u003cbody\u003e\n    \u003cimg onload=\"console.log('image 1 loaded');\" src=\"image1\"\u003e\n    \u003cimg onload=\"console.log('image 2 loaded');\" src=\"image2\"\u003e\n\n    \u003cscript src=\"http://cdn.bootcss.com/jquery/2.2.0/jquery.min.js\"\u003e\u003c/script\u003e\n    \u003cscript src=\"http://cdn.bootcss.com/require.js/2.1.18/require.min.js\"\u003e\u003c/script\u003e\n    \u003cscript\u003e\n        require(['main.js'], function() {});\n    \u003c/script\u003e\n\u003c/body\u003e\n\n\u003c/html\u003e\n```\n\n## main.js\n``` javascript\ndefine([\n    'domReady'\n], function (domReady) {\n    $(document).ready(function () {\n        console.log(document);\n        var childNodes = document.body.childNodes;\n        console.log('childNodes number: ' + childNodes.length);\n        for (var i = 0; i \u003c childNodes.length; i++) {\n            console.log(childNodes[i] + ': ' + childNodes[i].nodeType);\n        }\n        console.log('jquery domReady');\n    });\n    domReady(function () {\n        console.log('requirejs domReady');\n    });\n});\n```\n\n## 运行结果\n![qq 20160324152236](https://cloud.githubusercontent.com/assets/16483765/14011128/e66a667a-f1d6-11e5-967c-00b1857abb3c.png)\n\n\u003e **结论：**可以看到，jquery的ready方法在DOM树构建后即触发，而requirejs的domReady方法则是在所有资源被加载完毕之后触发，相当于window.onload。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsoon%2Frequirejs-domready","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsoon%2Frequirejs-domready","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsoon%2Frequirejs-domready/lists"}