clojurehiccup

How to add defer to script tag in hiccup?


I would like to add a defer attribute to a script tab in hiccup.

But things like [:script {:src "main.js" :defer}] return an error, and forms like [:script {:src "main.js"} :defer] insert "defer" in the middle of the script opening and closing tags.

Does anybody know how can i get something that translate to <script src="main.js" defer></script> ?


Solution

  • You need to add a value for a :defer map key:

    [:script {:src "main.js" :defer true}]

    It should generate:

    <script src="main.js" defer="true"></script>

    which is equivalent to:

    <script src="main.js" defer></script>