Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use async attribute in script tag in haml?

Tags:

html

haml

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
like image 846
IzumiSy Avatar asked Nov 25 '17 04:11

IzumiSy


People also ask

How do I use async attributes?

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.

What is async attribute in script tag?

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).

What are defer and async attributes on a script tag?

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.

Is script tag async by default?

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 .


1 Answers

%script{async: true, await: true, src: "hogehoge.com/test.js"}

I found that I could put those attributes to script tag with this syntax.

like image 119
IzumiSy Avatar answered Oct 16 '22 08:10

IzumiSy