0

enter image description hereenter image description here

I am getting error in the console after including the external js file like this in default_head_block.xml

2

1 Answer 1

0

Maybe you can try to include your js using require.config this way:

Create a new phtml file with this content:

<script>
   require.config({
       map: {
           '*': {
               'magnific-popup':  'https://cdnjs.....'
           }
       }
   });
</script>

Whenever your phtml is executed, above code will make an entry to requirejs-config.js file.

Then you can call that js in any other js file using define:

define(
    [
        'jquery',
        'magnific-popup' // here the js file is mapped
    ],
    function (
        $,
        popup // you can refer this object to use magnific-popup functions
    ) {
        'use strict';

     // js logic
});

In this way your js file will not be included in every page of the site but only in pages you really need it.

Hope it helps :)

2
  • this error is comming Commented Feb 21, 2020 at 10:45
  • Uncaught Error: Mismatched anonymous define() module: function ( $,magnificpopup) { 'use strict'; // js logic $('.blob').magnificPopup({type:'image',delegate:'a',gallery:{enabled:true}}); Commented Feb 21, 2020 at 10:45

Your Answer

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

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