| 255 | } |
| 256 | |
| 257 | const deferScript = scriptCode => { |
| 258 | // Mimic the behavior of a defer script by waiting until the DOM is loaded |
| 259 | // before executing the script. |
| 260 | return ` |
| 261 | (() => { |
| 262 | const run = (() => { |
| 263 | if (document.readyState === "interactive") { |
| 264 | ${scriptCode} |
| 265 | } |
| 266 | }); |
| 267 | |
| 268 | document.addEventListener('readystatechange', run, { once: true }); |
| 269 | })(); |
| 270 | `; |
| 271 | }; |
| 272 | |
| 273 | export const embedScript = (script, source, contents) => { |
| 274 | const code = contents ?? ''; |