3

In my Magento site, we found there was configuration in admin.

Admin -> Store -> Configuration -> Advanced -> Developer (Enabled only on Developer mode). JavaScript settings -> Move JS code to the bottom of the page

When this is YES, all the scripts tags on the site moves to the bottom of the page.

But I need to include a script which shouldn't move to the bottom.

Is there any way to achieve this?

Thanks in advance.

3
  • follow this link magento.stackexchange.com/questions/355/… and yes i know this link is magento 1 but you are include js file in xml file.And some edit xml file add before.body.end Commented May 7, 2020 at 17:41
  • Thanks for your Update. My scripts loads in via phtml. And I need to load avoid that particular script from moving to bottom. Commented May 8, 2020 at 4:24
  • Id recommend using MageFan module rather than the magento built in one as it is buggy magefan.com/rocket-javascript-deferred-javascript this allows you to acheive what you are after Commented Sep 9, 2020 at 19:10

4 Answers 4

6

I have developed a solution on my own. And submitted this as a blog.

Hope this helps for someone.

https://www.dckap.com/blog/exclude-script-from-magento-2-3/

Happy Coding..!!!

Thanks.

5

To exclude a particular tag from moving to the bottom of the page, simply add type="text/x-magento-template" to the script tag and it will remain where originally inserted via layout instruction.

See vendor\magento\module-theme\Controller\Result\JsFooterPlugin.php

Line 82:: $isXMagentoTemplate = strpos($script, 'text/x-magento-template') !== false;

0

Edit the JsFooterPlugin.php file in /vendor/magento/module-theme/Controller/Result and include an exception in the first conditional of public function beforeSendResponse

0

You can fix it by adding text/x-magento-template to that script. Example: < script exclude-this-tag="text/x-magento-template">

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.