HTML::O...:Script(3)

πŸ“¦ version 0.6.0, in alpine 3.24

🌸 NAME

HTML::Object::DOM::Element::Script β€” the HTML Object DOM Script Class, aka the little object that runs the show when your page says "hey, run this script" πŸ’…

Oh and real quick, bestie β€” this whole thing lives in the User Contributed Perl Documentation section of the manual, and the page you're reading is literally titled HTML::O...:Script(3) (they truncated it, the disrespect 😭). But it's the Script element page. Periodt.

✨ SYNOPSIS

Ok so the whole flex is like three lines:

use HTML::Object::DOM::Element::Script;
my $script = HTML::Object::DOM::Element::Script->new ||
    die( HTML::Object::DOM::Element::Script->error, "\n" );

That's it. That's the vibe. Create it or die trying 🫢

πŸŽ€ VERSION

We're on v0.2.0 β€” small number, big energy 🌈

πŸ’– DESCRIPTION

So what this class actually does: it implements the interface for <script elements. Yep β€” those scripty little guys. It gives you the special properties and methods for messing with how a <script element behaves and executes β€” everything beyond what it already inherits from the HTML::Object::Element interface. Main character energy, honestly πŸ‘‘

(And yes, the stray quote in <script is canon, it's in the original, ngl it's giving typo chic πŸ’€)

πŸ¦‹ INHERITANCE

Here's the whole family tree, bestie. It's a whole lineage:

+-----------------------+     +---------------------------+     +-------------------------+     +----------------------------+     +------------------------------------+
| HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Script |
+-----------------------+     +---------------------------+     +-------------------------+     +----------------------------+     +------------------------------------+

Look at all those ancestors. Generational talent, fr fr ✨

πŸ’œ PROPERTIES

It inherits properties from its parent HTML::Object::DOM::Element β€” so everything there is yours too, plus this stuff:

😴 async

So the async and defer attributes are boolean attributes, and they're the ones that control how the script gets executed. Lowkey important detail: the defer and async attributes must not be specified if the src attribute is absent. Not optional. Don't do it 🚫

There are three possible execution modes, and I need you to memorize these:

  1. If the async attribute is present, then the script will be executed asynchronously as soon as it downloads. Immediate slay.
  2. If the async attribute is absent but the defer attribute is present, then the script is executed when the page has finished parsing. Patient queen behavior.
  3. If neither attribute is present, then the script is fetched and executed immediately, blocking further parsing of the page. Rude of it, honestly, but that's the default.

The defer attribute may be specified with the async attribute β€” so legacy browsers that only support defer (and not async) fall back to the defer behavior instead of the default blocking behavior. Backwards compatibility icon 🫢

Note: the exact processing details for these attributes are complex β€” they involve many different aspects of HTML, so they're scattered all throughout the specification. These algorithms describe the core ideas, but they rely on the parsing rules for <script start and end tags in HTML, in foreign content, and in XML; the rules for the document.write() method; the handling of scripting; and so on. So like… it's complicated. Iykyk.

See also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/async

πŸ”€ charset

A string representing the character encoding of an external script. It reflects the charset attribute. Cute and simple πŸ’–

See also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/charset

🌍 crossOrigin

A string that reflects the CORS setting for the script element. For scripts coming from other origins, this controls whether error information will be exposed or not. Cross-origin drama, but make it configurable πŸ¦‹

See also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/crossOrigin

⏳ defer

The defer attribute may be specified even if the async attribute is specified β€” the whole point is to cause legacy web browsers that only support defer (and not async) to fall back to the defer behavior instead of the blocking behavior that is the default. Give the old browsers a soft landing πŸŽ€

πŸ“… event

It's a string β€” and it's an obsolete way of registering event handlers on elements in an HTML document. Deprecated, bestie. It's giving 2009. Don't build new stuff on it πŸ™ˆ

See also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/event

🚫 noModule

A boolean value that, if true, stops the script's execution in browsers that support ES2015 modules β€” used to run fallback scripts in older browsers that do not support JavaScript modules. It's the "you probably weren't invited" flag πŸ’…

See also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/noModule

πŸ•΅οΈ referrerPolicy

A string that reflects the referrerpolicy HTML attribute, indicating which referrer to use when fetching the script β€” and the fetches done by that script, too. It's a whole chain of trust situation.

Example time, look at this little cutie:

my $scriptElem = $doc->createElement( 'script' );
$scriptElem->src = '/';
$scriptElem->referrerPolicy = 'unsafe-url';
$doc->body->appendChild( $scriptElem );

See also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/referrerPolicy

πŸ”— src

A string representing the URL of an external script. It reflects the src HTML attribute. And the fun part: you can get and set an URI object on it. Flexible king πŸ‘‘

See also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/src

πŸ“ text

A string that joins and returns the contents of all Text nodes inside the <script element (ignoring other nodes like comments) in tree order. On setting, it acts the same way as the textContent IDL attribute. So it's basically the content but only the text bits, okurrr πŸ’–

Note: when inserted using the document.write() method, <script> elements execute (typically synchronously) β€” but when inserted using innerHTML or outerHTML, they do not execute at all. That's the trap. Write it down. 🚨

See also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/text

🏷️ type

A string representing the MIME type of the script. It reflects the type HTML attribute. Classic. Iconic. Essential.

See also Mozilla documentation https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement/type

πŸ”₯ METHODS

It inherits methods from its parent HTML::Object::DOM::Element β€” nothing extra listed here, and honestly the inherited toolkit is already a whole mood πŸ’…

πŸ‘‘ AUTHOR

Jacques Deguest <jack@deguest.jp> β€” the mastermind behind this whole thing. We stan 🫢

🌈 SEE ALSO

Go read the specs bestie, they're long but they're worth it πŸ’–

Copyright(c) 2021 DEGUEST Pte. Ltd.

All rights reserved

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Open source baddie behavior, we love to see it πŸ“


Alright that's the whole page! 🧚 Quick sign-off with the boring-but-required bits: this was generated by perl v5.42.2 and dated 2026-02-15 β€” so if you're reading this way in the future, hi, love you, the facts still hold πŸŒΈπŸ’œ

πŸ“¦ where this page comes from