Is it possible to add a script tag with the attribute type set to module e.g. type="module" in magento?

I'm trying to load a es6 module through the head of the xml file but it is not retrieving the script with the type module set.

This is the code:

enter image description here

This is the resultant script, as you can see the type attribute is being replaced with type="script/text"

enter image description here

1 Answer 1


You can not add type=module via xml. But here have an alternatives. You can create a block and add your script in template.phtml file after that assign this block into head section.

you can see this article for better understanding. https://php-scripts-form.blogspot.com/2023/06/loading-external-es6-script-modules-in.html

    <block class="Your\Module\Block\CustomScript" name="custom_script" template="Your_Module::custom_script.phtml" />

In the custom_script.phtml file, add your script tag with the type="module" attribute:

<script type="module">
    // Your ES6 module code here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.