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

Consider using WP Script Modules API #411

Open
tomalec opened this issue Mar 28, 2024 · 1 comment
Open

Consider using WP Script Modules API #411

tomalec opened this issue Mar 28, 2024 · 1 comment
Labels
priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. type: enhancement The issue is a request for an enhancement.

Comments

@tomalec
Copy link
Member

tomalec commented Mar 28, 2024

User story

As discussed in during the review of #398 (comment) our scripts would be more async and defer friendly. This could let us use the latest WP Script Modules API.

This could let us use a bit more modern standard, and write the code closer to the one actually executed in the browser.

Unfortunately, for now, we cannot switch yet.

  1. The API will be available in WP 6.5, which is not released yet, and we need to support older versions.
  2. WP API does not support inline modules. And we currently end data using inline scripts. So we would either need to change that approach, or wait for the support.
  3. The API does not support classic script dependencies, so we need to depend on classic inline script data (or change the approach). Most importantly, we depend on google-tag-manager, which needs to stay there.

Describe alternatives you've considered

Use classic scripts as we use today.

Acceptance criteria

Unknowns

Out of bounds/rabbit holes

Event tracking

@tomalec tomalec added the type: enhancement The issue is a request for an enhancement. label Mar 28, 2024
@tomalec
Copy link
Member Author

tomalec commented Mar 28, 2024

Speaking of loading the data via inline script, we could work it around as suggested in #398 (comment) by providing the data in HTML:

<wc-ga4w event-data="{JSON with data}">

Then, have a JS module that could define the custom element with no script dependency:

customElements.define( 'wc-ga4w', class extends HTMLElement{ 
	static observedAttributes = ["event-data"];
	attributeChangedCallback 
} );

but we still need to wait for WP 6.5 support, and solve the google-tag-manager script dependency.

@tomalec tomalec added the priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. label Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low The issue/PR is low priority—not many people are affected or there’s a workaround, etc. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

No branches or pull requests

1 participant