{"id":16370854,"url":"https://github.com/integralist/domready","last_synced_at":"2025-03-23T02:34:13.803Z","repository":{"id":140160596,"uuid":"1456278","full_name":"Integralist/DOMready","owner":"Integralist","description":"A cross browser 'DOM ready' function","archived":false,"fork":false,"pushed_at":"2012-07-01T14:26:52.000Z","size":4449,"stargazers_count":17,"open_issues_count":0,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-18T06:16:14.416Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/Integralist.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}},"created_at":"2011-03-08T20:33:23.000Z","updated_at":"2020-07-31T08:14:52.000Z","dependencies_parsed_at":"2023-03-13T10:44:18.888Z","dependency_job_id":null,"html_url":"https://github.com/Integralist/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/Integralist%2FDOMready","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2FDOMready/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2FDOMready/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Integralist%2FDOMready/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Integralist","download_url":"https://codeload.github.com/Integralist/DOMready/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221843067,"owners_count":16890251,"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-10-11T03:06:15.894Z","updated_at":"2024-10-28T14:47:46.053Z","avatar_url":"https://github.com/Integralist.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[Integralist](http://www.integralist.co.uk/) - DOMready\n================================\n\nDescription\n-----------\n\nA cross browser 'DOM ready' function.\n\nIf you don't know already, (usually) the best time to trigger your JavaScript functions is when the DOM (Document Object Model) is ready to be interacted with.\n\nIf you try and call a function which modifies an element in the DOM, but yet you're not waiting for the `window.onload` event then the function may fire before the DOM element is available to be interacted with and your script will generate an error.\n\nSo to avoid this, developers would write code that looked like this...\n\n`window.onload = function() { // do something here };`\n\n...but the problem was that it was just too slow for most developers to put up with. You want to be interacting with your DOM as soon as possible, but if you use the `window.onload` event then you're not just waiting for the DOM but all its content (such as images, stylesheets, iframes etc) to load as well.\n\nDevelopers needed something quicker, and so here comes the `DOMContentLoaded` event which fires when the browser has finished parsing the document but before the rest of the assets in the page (e.g. images, stylesheets, iframes etc) have finished loading.\n\nProblem is this event isn't supported cross-browser so developers have come up with a multitude of ways of mimicking this.\n\nThis script is one such way.\n\n\nDisclaimer\n----------\n\nThis DOMready function was originally a modified version of @ded's \"Smallest DOMReady code, ever' - but it quickly became apparent (thanks to @jdalton) that this version was sorely lacking and that although the work-around did 'work' it was very slow and in some browsers only marginally quicker than a simple window.onload.\n\nSo I reverted the code back to a previous version I had from a few years back.\n\nBut since then I've had feedback from both @jdalton and @diegoperini and implemented some essential updates to make this script as effective as possible.\n\nMy previous iterations (not on Github) have included at some point or another used...\n\n* For versions of Safari older than 525 (which didn't support DOMContentLoaded) use the `document.readyState` method.\n* For Internet Explorer: using Conditional Compilation `@cc_on @` along with `setInterval` to check the `doScroll` response\n* For Internet Explorer: `document.write` of deferred script\n* For Internet Explorer: checking for both `document.body \u0026\u0026 document.body.lastChild`\n* Checking for `document \u0026\u0026 document.getElementsByTagName \u0026\u0026 document.getElementById \u0026\u0026 document.body`\n\n\nMiscellaneous notes\n-------------\n\nDean Edwards `document.write` of the deferred script has given problems on some pages (causing a consistent \u003e 60 sec delay).\n\nDean also suggests that `document.readyState` is unreliable and that he has seen cases where `document.readyState` was \"complete\" while `document.body` was still `null`.\nAs well as other cases where `document.readyState` was not complete until after all images on the page were loaded.\n\nThe `doScroll` method has been seen to succeed while `document.body` is still `null`.\nAnd `document.body` can be non-null prior to the DOM being available.\n\nOne solution that so far has tested 100% OK is to combine a test for both `document.body` and success of `doScroll`.\nSometimes the `doScroll` is not available and Internet Explorer falls back to `window.onload` so some developers tried using a timer to counter this.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintegralist%2Fdomready","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintegralist%2Fdomready","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintegralist%2Fdomready/lists"}