-
-
Notifications
You must be signed in to change notification settings - Fork 527
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
Added 'async' optional param to 'regClientScript' and 'regClientStartupScript' #14527
Conversation
…ientStartupScript'
Need to update UnitTests for this PR |
* @return void | ||
*/ | ||
public function regClientStartupScript($src, $plaintext= false) { | ||
public function regClientStartupScript($src, $plaintext= false, $async='') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only two params allowed - async
and defer
, so we should add check if passed param is correct or just make it possible to turn it into a boolean parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed. now params checks correct values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add an attributes parameter. The script tag can also have other attributes like id
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are also other methods available (e.g. regClientHTML
) so I don't think we need an option for every possibility here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking about something like this:
public function regClientStartupScript($src, $plaintext= false, $attributes = [])
$attributes = ['async', 'defer', 'id' => ['test'], 'etc'];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are referring to W3 schools. Not the w3 specs.
See this list of supported attributes.
This also includes all global attributes.
This just needs the tests to be updated to get my approval. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failing tests need to be updated.
@DettRoxx if you need any help fixing the test please let us know 👍 |
Closing due to lack of interaction - if someone wants to pitch in to get this up to speed again that'd be awesome. |
What does it do?
Added optional param 'async' for methods regClientScript and regClientStartupScript of modx object, which allows to get
<script type="text/javascript" src="/assets/js/script.js" async></script>
or
<script type="text/javascript" src="/assets/js/script.js" defer></script>
instead of
<script type="text/javascript" src="/assets/js/script.js"></script>
Why is it needed?
to avoid "blocking-like" synchronous behaviour when browser builds DOM and stops and execute scripts tags, allows to use asynchronous behaviour instead
Related issue(s)/PR(s)
#14520