{"success":true,"name":"load-scripts-without-blocking-the-page","description":"Adding script tags, or the page shows white/blank while scripts load.","category":"ai-brimind","path":"ai-brimind/load-scripts-without-blocking-the-page/SKILL.md","file":"SKILL.md","content":"---\nname: load-scripts-without-blocking-the-page\ndescription: \"Adding script tags, or the page shows white/blank while scripts load.\"\n---\n\n# Load Scripts Without Blocking the Page\n\n## When to use\nProject is a website where script tags are being added to head/body, and their loading strategy (blocking, defer, async, order) hasn't been decided deliberately.\n\n## Example request\nLarge script in <head> without defer → the browser stops rendering HTML until it downloads and runs; users stare at white — parser-blocking script. Script runs before the DOM exists → getElementById returns null 'randomly' — execution before parsing finished. Analytics loaded blocking → a slow third-party delays YOUR page's render — external script on the critical path.\n\n## Instructions\nAct like a developer who knows a plain script tag means 'stop building the page and run this NOW'. Choose each script's loading mode deliberately: (1) DEFER is the sane default for your own code — downloads in parallel, executes after the HTML is parsed, preserves order between deferred scripts; it also eliminates the 'element is null' class of bugs without DOMContentLoaded wrappers; (2) ASYNC for independent third-party scripts (analytics) that don't touch your code and don't care about order — but never for scripts with dependencies, since async execution order is random; (3) plain blocking tags only when something genuinely must run before parsing continues — rare, and worth a comment saying why; (4) mind dependency order: if script B needs script A, both defer (order kept) or explicit loading logic — mixing async into a dependency chain creates intermittent works-sometimes bugs. Check the result: throttle the network in DevTools and watch whether content renders while scripts still download. Only proceed once every script tag's mode is chosen on purpose and the page renders visibly before non-critical scripts finish.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1116\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}