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

Added 'async' optional param to 'regClientScript' and 'regClientStartupScript' #14527

Open
wants to merge 2 commits into
base: 3.x
from

Conversation

Projects
None yet
4 participants
@DettRoxx
Copy link

commented Apr 2, 2019

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

@DettRoxx DettRoxx requested review from Mark-H and opengeek as code owners Apr 2, 2019

@DettRoxx

This comment has been minimized.

Copy link
Author

commented Apr 3, 2019

Need to update UnitTests for this PR

* @return void
*/
public function regClientStartupScript($src, $plaintext= false) {
public function regClientStartupScript($src, $plaintext= false, $async='') {

This comment has been minimized.

Copy link
@Alroniks

Alroniks Apr 3, 2019

Collaborator

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.

This comment has been minimized.

Copy link
@DettRoxx

DettRoxx Apr 3, 2019

Author

fixed. now params checks correct values

This comment has been minimized.

Copy link
@JoshuaLuckers

JoshuaLuckers Apr 3, 2019

Collaborator

We should add an attributes parameter. The script tag can also have other attributes like id.

This comment has been minimized.

Copy link
@Mark-H

Mark-H Apr 3, 2019

Collaborator

There are also other methods available (e.g. regClientHTML) so I don't think we need an option for every possibility here.

This comment has been minimized.

Copy link
@JoshuaLuckers

JoshuaLuckers Apr 4, 2019

Collaborator

I was thinking about something like this:

public function regClientStartupScript($src, $plaintext= false, $attributes = [])

$attributes = ['async', 'defer', 'id' => ['test'], 'etc'];

This comment has been minimized.

Copy link
@DettRoxx

DettRoxx Apr 4, 2019

Author

but for what? i opened w3 specs for 'script' tag:
we see:

image

This comment has been minimized.

Copy link
@JoshuaLuckers

JoshuaLuckers Apr 4, 2019

Collaborator

You are referring to W3 schools. Not the w3 specs.
See this list of supported attributes.
This also includes all global attributes.

@Mark-H

This comment has been minimized.

Copy link
Collaborator

commented Apr 5, 2019

This just needs the tests to be updated to get my approval.

@Mark-H Mark-H added this to the v3.0.0-alpha milestone Apr 5, 2019

@Mark-H
Copy link
Collaborator

left a comment

Failing tests need to be updated.

@JoshuaLuckers

This comment has been minimized.

Copy link
Collaborator

commented May 5, 2019

@DettRoxx if you need any help fixing the test please let us know 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.