I am getting error in the console after including the external js file like this in default_head_block.xml
1 Answer
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 :)
-
-
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