{"id":14852,"date":"2026-10-26T07:35:00","date_gmt":"2026-10-26T06:35:00","guid":{"rendered":"https:\/\/www.lukaswojcik.com\/blog\/?p=14852"},"modified":"2026-10-24T06:36:39","modified_gmt":"2026-10-24T04:36:39","slug":"script-position-in-the-html-document-what-a-script-without-defer-can-see","status":"publish","type":"post","link":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/","title":{"rendered":"Classic Scripts and the DOM: Finding Elements at the Right Time"},"content":{"rendered":"<p>A <strong>classic script processed by the HTML parser, without <code>async<\/code> or effective <code>defer<\/code><\/strong>, pauses further HTML parsing during execution. Elements appearing later in the source are normally not yet in the document tree (DOM). Modules, asynchronous scripts and dynamically inserted scripts follow different rules.<\/p>\n<p>This explains a common theme-switching failure: the header toggle works, but the first page load does not find images in the article below. All image files may be available; the query simply runs too early.<\/p>\n<figure class=\"lw-diagram\"><img decoding=\"async\" src=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/diagrams\/quality-14852-20261024.png\" width=\"1120\" height=\"580\" loading=\"lazy\" alt=\"Isolated test: zero figures during parsing, two after parsing and one scheduled image swap\"><figcaption>Test on 24 October 2026 in Chromium: two figures after the head script. The figures describe this fixture, not historical page traffic.<\/figcaption><\/figure>\n<h2>Source position is not a runtime measurement<\/h2>\n<p>A byte position describes order in the delivered HTML. Counting opening tags does not automatically count existing DOM elements: comments, script text, implicitly created elements and later changes can affect the result. Earlier scripts can also have inserted additional elements.<\/p>\n<p>A useful test therefore records <code>document.readyState<\/code> and the actual matches at execution time. The earlier page-size and file-count figures are not presented here as reproduced measurements. A small isolated browser example demonstrates the mechanism instead.<\/p>\n<h2>What the browser test demonstrates<\/h2>\n<p>In the test dated 24 October 2026, two <code>figure<\/code> elements follow a classic script in the head. The early query finds zero figures. An external classic script with <code>defer<\/code> and an ordinary module later find both figures. Adding <code>defer<\/code> to the inline classic script does not postpone execution.<\/p>\n<p><code>querySelectorAll()<\/code> also returns a static list. The empty list captured early remains empty even after both figures exist. A fresh query is therefore needed after parsing. This was an isolated Chromium test, not a cross-browser matrix or a historical network capture of the website.<\/p>\n<h2>Why a later click is not enough<\/h2>\n<p>A click after parsing tests a state change with the elements already present. That does not establish correct behaviour during the initial load. A click can also occur while loading continues, once the control is visible and an event handler is attached.<\/p>\n<p>A saved light preference, a reload in dark mode and a switch during loading are consequently separate test cases. The current theme state matters for each image swap. Existing header elements do not establish that the article figures below have already been created.<\/p>\n<h2>Schedule the image swap after parsing<\/h2>\n<p>The following integration example requires an existing <code>bilderJetztTauschen(hell)<\/code> function. That function must query the current images again on every call and set the appropriate addresses. The snippet only controls when execution happens.<\/p>\n<pre><code>const wurzel = document.documentElement;\nlet bildtauschGeplant = false;\n\nfunction bilderTauschen(hell) {\n    if (document.readyState === &#x27;loading&#x27;) {\n        if (bildtauschGeplant) return;\n        bildtauschGeplant = true;\n        document.addEventListener(&#x27;DOMContentLoaded&#x27;, function () {\n            bildtauschGeplant = false;\n            bilderJetztTauschen(wurzel.getAttribute(&#x27;data-theme&#x27;) === &#x27;light&#x27;);\n        }, { once: true });\n        return;\n    }\n    bilderJetztTauschen(hell);\n}<\/code><\/pre>\n<p>While <code>readyState<\/code> is <code>loading<\/code>, at most one listener is registered. When the event fires, the current preference is read from <code>data-theme<\/code>. After parsing, the function calls the image swap immediately with the supplied value. The root element must reflect the selection before this function is called.<\/p>\n<p>In the isolated test, three early calls produced exactly one later swap using the latest light preference. A subsequent call with the dark preference ran immediately. This is an improved example; the production theme was not changed as part of this article review.<\/p>\n<div class=\"lw-faq\">\n<h2>Questions and answers<\/h2>\n<h3>When do defer and modules help?<\/h3>\n<p>For external classic scripts, <code>defer<\/code> schedules execution after HTML parsing and preserves document order. Ordinary modules also execute after parsing. <code>async<\/code> does not provide that guarantee; execution depends on script availability. For modules, <code>async<\/code> can matter even without a <code>src<\/code> on the module itself. Both <code>defer<\/code> and <code>async<\/code> have no effect on inline classic scripts.<\/p>\n<h3>Why DOMContentLoaded instead of load?<\/h3>\n<p><code>DOMContentLoaded<\/code> follows HTML parsing and the associated deferred scripts. The event does not wait for all images or asynchronous scripts; stylesheets can delay execution indirectly through waiting scripts. <code>load<\/code> waits for additional page resources but excludes lazily loaded images. For required web fonts, <code>document.fonts.ready<\/code> is the targeted check. Finding the figures only requires the parsed document tree.<\/p>\n<h3>Does swapping prevent duplicate image transfers?<\/h3>\n<p>No. Preload scanning or image loading may already have requested the original address. Caching, loading distance, connection and browser behaviour determine the actual cost; <code>loading=\"lazy\"<\/code> does not guarantee that a request is avoided. Network logs provide better evidence than script position.<\/p>\n<p><code>&lt;picture&gt;<\/code> with <code>prefers-color-scheme<\/code> can follow the system preference. A selection held only in <code>localStorage<\/code> is neither readable by CSS media queries nor automatically known to the server. Server-side selection requires separately transmitting that state.<\/p>\n<h3>What about articles inserted later?<\/h3>\n<p><code>DOMContentLoaded<\/code> does not fire again for the same document. A content change without full navigation needs a separate call after insertion. In the test, inserting a third figure later did not automatically trigger another swap.<\/p>\n<\/div>\n<div class=\"lw-quellen\">\n<h2>Sources<\/h2>\n<ul>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Reference\/Elements\/script\" target=\"_blank\" rel=\"noopener noreferrer\">MDN: script element<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Document\/DOMContentLoaded_event\" target=\"_blank\" rel=\"noopener noreferrer\">MDN: DOMContentLoaded<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Window\/load_event\" target=\"_blank\" rel=\"noopener noreferrer\">MDN: load event<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Document\/querySelectorAll\" target=\"_blank\" rel=\"noopener noreferrer\">MDN: querySelectorAll<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/FontFaceSet\/ready\" target=\"_blank\" rel=\"noopener noreferrer\">MDN: FontFaceSet.ready<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Reference\/Elements\/img\" target=\"_blank\" rel=\"noopener noreferrer\">MDN: img and lazy loading<\/a><\/li>\n<li><a href=\"https:\/\/html.spec.whatwg.org\/multipage\/scripting.html#the-script-element\" target=\"_blank\" rel=\"noopener noreferrer\">WHATWG: script processing<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Classic scripts can query the document before article images exist. An isolated browser test explains defer, modules, static query results and a single scheduled image swap after parsing.<\/p>\n","protected":false},"author":1,"featured_media":24205,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[148],"tags":[91312,91315,91096],"class_list":["post-14852","post","type-post","status-publish","format-standard","hentry","category-web-development","tag-javascript","tag-web-performance","tag-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Classic Scripts and the DOM: Finding Elements at the Right Time | Lukas Wojcik<\/title>\n<meta name=\"description\" content=\"A theme script swapped images for light mode and found nothing on page load. Measured at byte level: the script sat at 42.4 per cent of the document, and every element it needed came after it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Classic Scripts and the DOM: Finding Elements at the Right Time | Lukas Wojcik\" \/>\n<meta property=\"og:description\" content=\"A theme script swapped images for light mode and found nothing on page load. Measured at byte level: the script sat at 42.4 per cent of the document, and every element it needed came after it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/\" \/>\n<meta property=\"og:site_name\" content=\"Lukas Wojcik - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-26T06:35:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/10\/quality-hero-14852-20261024.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Lukas Wojcik\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lukas Wojcik\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/\"},\"author\":{\"name\":\"Lukas Wojcik\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"headline\":\"Classic Scripts and the DOM: Finding Elements at the Right Time\",\"datePublished\":\"2026-10-26T06:35:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/\"},\"wordCount\":750,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"image\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/quality-hero-14852-20261024.png\",\"keywords\":[\"JavaScript\",\"Web Performance\",\"WordPress\"],\"articleSection\":[\"Web Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/\",\"name\":\"Classic Scripts and the DOM: Finding Elements at the Right Time | Lukas Wojcik\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/quality-hero-14852-20261024.png\",\"datePublished\":\"2026-10-26T06:35:00+00:00\",\"description\":\"A theme script swapped images for light mode and found nothing on page load. Measured at byte level: the script sat at 42.4 per cent of the document, and every element it needed came after it.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/quality-hero-14852-20261024.png\",\"contentUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/quality-hero-14852-20261024.png\",\"width\":1200,\"height\":630,\"caption\":\"Classic Scripts and the DOM: Finding Elements at the Right Time\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/web-development\\\/script-position-in-the-html-document-what-a-script-without-defer-can-see\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Classic Scripts and the DOM: Finding Elements at the Right Time\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/\",\"name\":\"Lukas Wojcik - Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\",\"name\":\"Lukas Wojcik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"contentUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"width\":424,\"height\":636,\"caption\":\"Lukas Wojcik\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\"},\"sameAs\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Classic Scripts and the DOM: Finding Elements at the Right Time | Lukas Wojcik","description":"A theme script swapped images for light mode and found nothing on page load. Measured at byte level: the script sat at 42.4 per cent of the document, and every element it needed came after it.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/","og_locale":"en_US","og_type":"article","og_title":"Classic Scripts and the DOM: Finding Elements at the Right Time | Lukas Wojcik","og_description":"A theme script swapped images for light mode and found nothing on page load. Measured at byte level: the script sat at 42.4 per cent of the document, and every element it needed came after it.","og_url":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/","og_site_name":"Lukas Wojcik - Blog","article_published_time":"2026-10-26T06:35:00+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/10\/quality-hero-14852-20261024.png","type":"image\/png"}],"author":"Lukas Wojcik","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Lukas Wojcik","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/#article","isPartOf":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/"},"author":{"name":"Lukas Wojcik","@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"headline":"Classic Scripts and the DOM: Finding Elements at the Right Time","datePublished":"2026-10-26T06:35:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/"},"wordCount":750,"commentCount":0,"publisher":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"image":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/10\/quality-hero-14852-20261024.png","keywords":["JavaScript","Web Performance","WordPress"],"articleSection":["Web Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/","url":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/","name":"Classic Scripts and the DOM: Finding Elements at the Right Time | Lukas Wojcik","isPartOf":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/#primaryimage"},"image":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/10\/quality-hero-14852-20261024.png","datePublished":"2026-10-26T06:35:00+00:00","description":"A theme script swapped images for light mode and found nothing on page load. Measured at byte level: the script sat at 42.4 per cent of the document, and every element it needed came after it.","breadcrumb":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/#primaryimage","url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/10\/quality-hero-14852-20261024.png","contentUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/10\/quality-hero-14852-20261024.png","width":1200,"height":630,"caption":"Classic Scripts and the DOM: Finding Elements at the Right Time"},{"@type":"BreadcrumbList","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/web-development\/script-position-in-the-html-document-what-a-script-without-defer-can-see\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.lukaswojcik.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Classic Scripts and the DOM: Finding Elements at the Right Time"}]},{"@type":"WebSite","@id":"https:\/\/www.lukaswojcik.com\/blog\/#website","url":"https:\/\/www.lukaswojcik.com\/blog\/","name":"Lukas Wojcik - Blog","description":"","publisher":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.lukaswojcik.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9","name":"Lukas Wojcik","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","contentUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","width":424,"height":636,"caption":"Lukas Wojcik"},"logo":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg"},"sameAs":["https:\/\/www.lukaswojcik.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/14852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/comments?post=14852"}],"version-history":[{"count":6,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/14852\/revisions"}],"predecessor-version":[{"id":24229,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/14852\/revisions\/24229"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/media\/24205"}],"wp:attachment":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/media?parent=14852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/categories?post=14852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/tags?post=14852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}