Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude JS from move JS code to the bottom of the page #34946

Closed
wants to merge 0 commits into from

Conversation

in-session
Copy link
Contributor

Currently there is no possibility to exclude global single files or inline scripts with the function "Move JS code to the bottom of the page". However, this is necessary in some areas, for example with the Google Tag Manager or other critical JS resources.

Configuration>Developer>JavaScript Settings>Move JS code to the bottom of the page

@m2-assistant
Copy link

m2-assistant bot commented Jan 7, 2022

Hi @in-session. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.

For more details, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@in-session
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@Den4ik Den4ik added the Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. label Jan 12, 2022
@m2-community-project m2-community-project bot added this to Pending Review in Pull Requests Dashboard Jan 12, 2022
@Den4ik Den4ik self-assigned this Jan 12, 2022
@Den4ik Den4ik self-requested a review January 12, 2022 19:52
@m2-community-project m2-community-project bot moved this from Pending Review to Review in Progress in Pull Requests Dashboard Jan 12, 2022
@Den4ik
Copy link
Contributor

Den4ik commented Jan 12, 2022

@magento run Functional Tests B2B, Functional Tests EE, Functional Tests CE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Copy link
Contributor

@Den4ik Den4ik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @in-session.
Thanks for PR.
I believe that we can remove data-move="false" string from result context after detection.
What do you think?

@m2-community-project m2-community-project bot moved this from Review in Progress to Changes Requested in Pull Requests Dashboard Jan 12, 2022
@in-session
Copy link
Contributor Author

in-session commented Jan 12, 2022

Hi @in-session. Thanks for PR. I believe that we can remove data-move="false" string from result context after detection. What do you think?

@Dan4ik
Do you have an idea for that? I am a bit overwhelmed with work right now.

@sdzhepa sdzhepa added the Priority: P3 May be fixed according to the position in the backlog. label Jan 13, 2022
@mrtuvn
Copy link
Contributor

mrtuvn commented Jan 16, 2022

So if in file xml layout dev add specific file external/custom js files have attribute "data-move" equal false magento will act not move these files to bottom ?
For very specific case i think the better option is instead excludition by code we can choose conditional include or load
Can you add some content for clarify idea of this improve?

From my experiences with requirejs in magento stack current if we require it somewhere in js codebase you cannot remove it from layout. The only way for exclude is find place where it define and add some condition or remove it completely

@in-session
Copy link
Contributor Author

in-session commented Jan 16, 2022

So if in file xml layout dev add specific file external/custom js files have attribute "data-move" equal false magento will act not move these files to bottom ? For very specific case i think the better option is instead excludition by code we can choose conditional include or load Can you add some content for clarify idea of this improve?

From my experiences with requirejs in magento stack current if we require it somewhere in js codebase you cannot remove it from layout. The only way for exclude is find place where it define and add some condition or remove it completely
@mrtuvn

Yes the idea behind it is to exclude scripts from moving
For example with the use of third cookie consent tools or other libraries like workbox etc., these must not be loaded async and must be added on top, like:

<script src="https://privacy-proxy.usercentrics.eu/latest/uc-block.bundle.js" src_type="url" data-move="false" />

But of course this also refers to inline scripts which are integrated via phtml, like google tag manager:

<?php
$scriptTagManager = <<<SCRIPT
    (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','GTM-XXXXXX');
SCRIPT;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', ['data-cfasync'=>'false','data-move'=>'false'], $scriptTagManager, false) ?>

You can find many entries of the missing function:
https://www.google.com/search?q=magento+2+exclude+js+move+bottom+&sxsrf=AOaemvI_7G8jjy9sbgXZgj_BLi3JiOZBXA%3A1642320634993&ei=-tLjYcTpO7OW9u8P49uxsAg&ved=0ahUKEwjEzriQ6bX1AhUzi_0HHeNtDIYQ4dUDCA4&uact=5&oq=magento+2+exclude+js+move+bottom+&gs_lcp=Cgdnd3Mtd2l6EAMyBQgAEM0CMgUIABDNAjoHCAAQRxCwAzoICCEQFhAdEB5KBAhBGABKBAhGGABQ3l9Y7pABYIqUAWgFcAJ4AIABhQGIAeoIkgEEMTMuMZgBAKABAaABAsgBCMABAQ&sclient=gws-wiz

@vseager
Copy link
Contributor

vseager commented Feb 15, 2023

@in-session what is the status on this?

@in-session
Copy link
Contributor Author

@vseager
Due to time constraints I can't continue right now. You are welcome to make suggestions for changes.
With me it currently runs only the test has not gone through.

@in-session
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@in-session
Copy link
Contributor Author

Hi @in-session. Thanks for PR. I believe that we can remove data-move="false" string from result context after detection. What do you think?

I would say no as it is better for frontend debugging to check the values.

@in-session
Copy link
Contributor Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@sinhaparul sinhaparul added the Project: Community Picked PRs upvoted by the community label May 21, 2024
@m2-community-project m2-community-project bot added this to Changes Requested in Community Dashboard May 21, 2024
@m2-community-project m2-community-project bot removed this from Changes Requested in Pull Requests Dashboard May 21, 2024
@engcom-Bravo engcom-Bravo added the Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it label May 22, 2024
@engcom-Echo
Copy link
Contributor

@in-session Can you please resolved the conflicts?

@in-session
Copy link
Contributor Author

@magento run all tests

Copy link

Pull Requests are not mergeable to the mainline. Please merge the latest mainlines to your Pull Requests and restart the builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Theme Component: View Priority: P3 May be fixed according to the position in the backlog. Project: Community Picked PRs upvoted by the community Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants