seeking some advises. My Magento-2 project has 2 custom JS files that I would like replicated and loaded externally on the site. This arrangement is for our client to use them to add his own code changes and deploy them directly to the production server whenever he makes minor changes in these JS files. Just to give you an example, he wants to change the logo every holiday for which he can deploy these JS files as soon once the logo is changed and stash this file once the holiday is over. All I need to know is what location is ideal for saving external files and how to load and execute them on the Magento site using some function? How do I invoke this?


Try this way



var config = {
    map: {
                                 deps: ['jquery']



    function($, dom, custom_js){

        $(document).on('click', '.list-product', function(event){
            console.log("Call custom Js");

Add this into your phtml file

<button type="button" class="list-product" data-mage-init='{"custom_js":{}}' >Click Me!</button>

Note: above code is for frontend only.

I Hope This Helps You.

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.