Constant defer

Source
pub const defer: AttributeDescription;
Expand description

This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed, but before firing DOMContentLoaded.

Scripts with the defer attribute will prevent the DOMContentLoaded event from firing until the script has loaded and finished evaluating.


§Warning:

This attribute must not be used if the src attribute is absent (i.e. for inline scripts), in this case it would have no effect.


The defer attribute has no effect on module scripts — they defer by default. Scripts with the defer attribute will execute in the order in which they appear in the document.

This attribute allows the elimination of parser-blocking JavaScript where the browser would have to load and evaluate scripts before continuing to parse. async has a similar effect in this case.

§Usage in rsx

let defer = "value";

rsx! {
    // Attributes need to be under the element they modify
    script {
        // Attributes are followed by a colon and then the value of the attribute
        defer: "value"
    }
    script {
        // Or you can use the shorthand syntax if you have a variable in scope that has the same name as the attribute
        defer,
    }
};