Can you please suggest us how to load js into the custom module created? We are facing issues in loading the js to our custom module created


Method 1:

Create File in app/code/Vendor/Module/view/frontend/layout/default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
       <!--js file -->
       <script src="Vendor_Module::js/abcd.js"/>

Then put abcd.js file inside App/Code/Vendor/Module/View/Frontend/web/js/

Method 2:

Add js using requirejs-config.js file

Create file app/design/frontend/Vendor/Module/view/frontend/web/requirejs-config.js

var config = {
    map: {
        '*': {

And call in any template customjs script tag like as

<script>// <![CDATA[
    ], function ($, script) {
        //Your code here
    // ]]>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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