{"id":99426,"date":"2017-10-13T13:47:01","date_gmt":"2017-10-13T13:47:01","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=99426"},"modified":"2024-03-27T12:56:24","modified_gmt":"2024-03-27T12:56:24","slug":"call-configurable-external-js-url-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/","title":{"rendered":"How to call a configurable external JS URL in magento2"},"content":{"rendered":"\n<p>How to call a configurable external JS URL in magento2<\/p>\n\n\n\n<p>Today I will explain in this article, that how you can create a configurable JS external URL and then map it with another js in magento 2. Suppose you stuck in a condition, i.e. you have to call only one JS with some conditions, like if mode is production then ABC.js should call and if mode is desug then XYZ.js should call , so this blog will be very helpful for you. So lets get started. At first you will need to call a template file on your page, i.e. <strong>test.phtml<\/strong>. In this file write the configurable JS url, for e.g. :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php if ($mode == &quot;production&quot;) {\n    $url = &quot;https:\/\/abc.production\/payment.js&quot;;\n  \n} else {\n    $url = &quot;https:\/\/abc.sandbox\/payment.js&quot;;\n} ?&gt;\n\/\/ $url :- You can use any external js url\n&lt;script&gt;\n   require.config({\n       map: {\n           &#039;*&#039;: {\n               &#039;customjs&#039;:  &#039;&lt;?= $url ?&gt;&#039;\n           }\n       }\n   });\n&lt;\/script&gt;<\/pre>\n\n\n\n<p>Whenever <strong>test.phtml<\/strong> is executed, the above code will make an entry to\u00a0requirejs-config.js \u00a0file. Now how do you call this in your other JS files? You have to add the below code after the above code in the same file to call another js.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;script type=&quot;text\/x-magento-init&quot;&gt;\n    {\n        &quot;*&quot;: {\n             &quot;newcustomjs&quot;:{}\n        }\n    }\n&lt;\/script&gt;<\/pre>\n\n\n\n<p>So let&#8217;s have a look below in your other <strong>newcustomjs.js<\/strong> file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">\/*browser:true*\/\n\/*global define*\/\ndefine(\n    &#091;\n        &#039;ko&#039;,\n        &#039;jquery&#039;,\n        &#039;Magento_Checkout\/js\/view\/payment\/default&#039;,\n        &#039;Magento_Checkout\/js\/model\/quote&#039;,\n        &#039;customjs&#039; \/\/ here the js file is mapped\n    ],\n    function (\n        ko,\n        $,\n        Component,\n        quote,\n        custom \/\/ you can refer this object to use customjs functions\n    ) {\n        &#039;use strict&#039;;\n        \n        ...........\n        \/\/ and you can call your customjs functions easily\n        .........\n});<\/pre>\n\n\n\n<p>Now when <strong>newcustomjs.js<\/strong> is called then only your <strong>customjs<\/strong> file is invoked. Hope this blog will help you to build applications in your module in a better way.&nbsp;Try this and&nbsp;if you have any queries then&nbsp;just comment below \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to call a configurable external JS URL in magento2 Today I will explain in this article, that how you can create a configurable JS external URL and then map it with another js in magento 2. Suppose you stuck in a condition, i.e. you have to call only one JS with some conditions, like <a href=\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":103,"featured_media":98036,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[2070],"class_list":["post-99426","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento2","tag-magento2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to call a configurable external JS URL in magento2 - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to call a configurable external JS URL in magento2 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"How to call a configurable external JS URL in magento2 Today I will explain in this article, that how you can create a configurable JS external URL and then map it with another js in magento 2. Suppose you stuck in a condition, i.e. you have to call only one JS with some conditions, like [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-10-13T13:47:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-27T12:56:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/10\/Magneto-Code-Snippet-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"825\" \/>\n\t<meta property=\"og:image:height\" content=\"260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Pranjali Goel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pranjali Goel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/\"},\"author\":{\"name\":\"Pranjali Goel\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c1964884ceb33a5ffdf322ee5424f692\"},\"headline\":\"How to call a configurable external JS URL in magento2\",\"datePublished\":\"2017-10-13T13:47:01+00:00\",\"dateModified\":\"2024-03-27T12:56:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/\"},\"wordCount\":227,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/10\/Magneto-Code-Snippet-1.png\",\"keywords\":[\"Magento2\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/\",\"name\":\"How to call a configurable external JS URL in magento2 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/10\/Magneto-Code-Snippet-1.png\",\"datePublished\":\"2017-10-13T13:47:01+00:00\",\"dateModified\":\"2024-03-27T12:56:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/10\/Magneto-Code-Snippet-1.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/10\/Magneto-Code-Snippet-1.png\",\"width\":825,\"height\":260,\"caption\":\"Optimisation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to call a configurable external JS URL in magento2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c1964884ceb33a5ffdf322ee5424f692\",\"name\":\"Pranjali Goel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e670273251719f83735534af186231dd99fbe378466fef356d4e55de5b46244f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e670273251719f83735534af186231dd99fbe378466fef356d4e55de5b46244f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Pranjali Goel\"},\"description\":\"Believes in simple lifestyle and follow a simple logic to make herself better than yesterday.\",\"url\":\"https:\/\/webkul.com\/blog\/author\/pranjali968\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to call a configurable external JS URL in magento2 - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/","og_locale":"en_US","og_type":"article","og_title":"How to call a configurable external JS URL in magento2 - Webkul Blog","og_description":"How to call a configurable external JS URL in magento2 Today I will explain in this article, that how you can create a configurable JS external URL and then map it with another js in magento 2. Suppose you stuck in a condition, i.e. you have to call only one JS with some conditions, like [...]","og_url":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2017-10-13T13:47:01+00:00","article_modified_time":"2024-03-27T12:56:24+00:00","og_image":[{"width":825,"height":260,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/10\/Magneto-Code-Snippet-1.png","type":"image\/png"}],"author":"Pranjali Goel","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Pranjali Goel","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/"},"author":{"name":"Pranjali Goel","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c1964884ceb33a5ffdf322ee5424f692"},"headline":"How to call a configurable external JS URL in magento2","datePublished":"2017-10-13T13:47:01+00:00","dateModified":"2024-03-27T12:56:24+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/"},"wordCount":227,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/10\/Magneto-Code-Snippet-1.png","keywords":["Magento2"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/","url":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/","name":"How to call a configurable external JS URL in magento2 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#primaryimage"},"thumbnailUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/10\/Magneto-Code-Snippet-1.png","datePublished":"2017-10-13T13:47:01+00:00","dateModified":"2024-03-27T12:56:24+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/10\/Magneto-Code-Snippet-1.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/10\/Magneto-Code-Snippet-1.png","width":825,"height":260,"caption":"Optimisation"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/call-configurable-external-js-url-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to call a configurable external JS URL in magento2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c1964884ceb33a5ffdf322ee5424f692","name":"Pranjali Goel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e670273251719f83735534af186231dd99fbe378466fef356d4e55de5b46244f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e670273251719f83735534af186231dd99fbe378466fef356d4e55de5b46244f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Pranjali Goel"},"description":"Believes in simple lifestyle and follow a simple logic to make herself better than yesterday.","url":"https:\/\/webkul.com\/blog\/author\/pranjali968\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/99426","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/103"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=99426"}],"version-history":[{"count":9,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/99426\/revisions"}],"predecessor-version":[{"id":429864,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/99426\/revisions\/429864"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media\/98036"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=99426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=99426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=99426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}