Skip to main content
Tweeted twitter.com/StackMagento/status/1225071720316514305
added 175 characters in body
Source Link
amitshree
  • 7.1k
  • 12
  • 64
  • 120

I'm trying to add external js in my module which will be applicable on all pages on frontend. This is the process I've followed:

  1. Code in my layout file app/code/Lapisbard/General/view/frontend/layout/default.xml

  2. Added js file at app/code/Lapisbard/General/view/frontend/web/js/ro_allpage.js with following code

    define('js/theme', [ 'jquery', 'domReady!' ], function ($) { 'use strict'; console.log('Hello'); }); I see my file is being added on the page but it throws console error Uncaught ReferenceError: define is not defined. What I'm doing wrong?
    Also I tried code below which throws Uncaught ReferenceError: require is not defined

    require(["jquery"], function($){ console.log("hello"); });

I'm trying to add external js in my module which will be applicable on all pages on frontend. This is the process I've followed:

  1. Code in my layout file app/code/Lapisbard/General/view/frontend/layout/default.xml

  2. Added js file at app/code/Lapisbard/General/view/frontend/web/js/ro_allpage.js with following code

    define('js/theme', [ 'jquery', 'domReady!' ], function ($) { 'use strict'; console.log('Hello'); }); I see my file is being added on the page but it throws console error Uncaught ReferenceError: define is not defined. What I'm doing wrong?

I'm trying to add external js in my module which will be applicable on all pages on frontend. This is the process I've followed:

  1. Code in my layout file app/code/Lapisbard/General/view/frontend/layout/default.xml

  2. Added js file at app/code/Lapisbard/General/view/frontend/web/js/ro_allpage.js with following code

    define('js/theme', [ 'jquery', 'domReady!' ], function ($) { 'use strict'; console.log('Hello'); }); I see my file is being added on the page but it throws console error Uncaught ReferenceError: define is not defined. What I'm doing wrong?
    Also I tried code below which throws Uncaught ReferenceError: require is not defined

    require(["jquery"], function($){ console.log("hello"); });

Source Link
amitshree
  • 7.1k
  • 12
  • 64
  • 120

Magento2: Add external JS globally

I'm trying to add external js in my module which will be applicable on all pages on frontend. This is the process I've followed:

  1. Code in my layout file app/code/Lapisbard/General/view/frontend/layout/default.xml

  2. Added js file at app/code/Lapisbard/General/view/frontend/web/js/ro_allpage.js with following code

    define('js/theme', [ 'jquery', 'domReady!' ], function ($) { 'use strict'; console.log('Hello'); }); I see my file is being added on the page but it throws console error Uncaught ReferenceError: define is not defined. What I'm doing wrong?