How to add attributes like async
or defer
in script tag in Haml? I tried to put it on a same line as href, but it does not work.
%a.twitter-share-button{href: "https://twitter.com/share?ref_src=twsrc%5Etfw", data: { url: "http://example.net", show: { count: "false" } } } Tweet
Definition and UsageIf the async attribute is set, the script is downloaded in parallel to parsing the page, and executed as soon as it is available. The parsing of the page is interrupted once the script is downloaded completely, and then the script is executed, before the parsing of the rest of the page continues.
The async attribute is a boolean attribute. When present, it specifies that the script will be executed asynchronously as soon as it is available. Note: The async attribute is only for external scripts (and should only be used if the src attribute is present).
Async - means execute code when it is downloaded and do not block DOM construction during downloading process. Defer - means execute code after it's downloaded and browser finished DOM construction and rendering process.
Dynamic scripts behave as “async” by default. This can be changed if we explicitly set script. async=false . Then scripts will be executed in the document order, just like defer .
%script{async: true, await: true, src: "hogehoge.com/test.js"}
I found that I could put those attributes to script tag with this syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With