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

Defer attribute #2

Open
Paulsky opened this issue Jun 9, 2018 · 3 comments
Open

Defer attribute #2

Paulsky opened this issue Jun 9, 2018 · 3 comments

Comments

@Paulsky
Copy link

Paulsky commented Jun 9, 2018

Just tested this module for Magento 2.2.4 and it seems to be working. The Javascript is placed before the closing body tag.

But I expected to have the script tags containg the defer="defer" attribute. Is there a reason for this and is it possible to add the attribute?

Thank you in advance!

@fballiano
Copy link
Owner

As far as I know (https://www.w3schools.com/tags/att_script_defer.asp) the defer attribute has to be used only for external scripts but:

  • we're "moving" all the scripts to the end of the page
  • there are both external and inline scripts
  • if we defer the external we may be facing the situation where some inline scripts are run before the external causing error

am I missing something?

@Paulsky
Copy link
Author

Paulsky commented Jun 14, 2018

Sorry, I didn't know the attribute has to be used only for external scripts. I have seen a couple of 'optimization' plugins which are setting the defer attribute, even though those scripts are internal scripts.

And I think you are right about the fact that there may be situations where some inline scripts run before the dependencies are loaded.

Could it be possible create an option in the module to opt-in include the defer attribute?

@fballiano
Copy link
Owner

I don't know, it seems to me that maybe we can cause more problems, would we add an option to "defer every script"? or should it be done for every single script (which is almost impossible to do)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants