I am getting error in the console after including the external js file like this in default_head_block.xml
-
check this post magento.stackexchange.com/questions/225917/…Yash Patadia– Yash Patadia2020-02-21 06:53:36 +00:00Commented Feb 21, 2020 at 6:53
-
any other solutionSubrat Panda– Subrat Panda2020-02-21 07:05:33 +00:00Commented Feb 21, 2020 at 7:05
Add a comment
|
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 :)
-
this error is commingSubrat Panda– Subrat Panda2020-02-21 10:45:42 +00:00Commented 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}});Subrat Panda– Subrat Panda2020-02-21 10:45:46 +00:00Commented Feb 21, 2020 at 10:45

