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

Leverage new Scripts API strategy attribute to improve performance #506

Open
adamsilverstein opened this issue Aug 11, 2023 · 10 comments · May be fixed by #507 or #508
Open

Leverage new Scripts API strategy attribute to improve performance #506

adamsilverstein opened this issue Aug 11, 2023 · 10 comments · May be fixed by #507 or #508

Comments

@adamsilverstein
Copy link

adamsilverstein commented Aug 11, 2023

Hello MonsterInsights Team!

I have been working on the WordPress core performance team helping research performance issues in by investigating blocking script usage that could leverage the new core Scripts API strategy feature.

While working on a query that uses httparchive data to see which scripts are most commonly “blocking” on WordPress sites (by "blocking" I mean in the head section and not marked as async or defer) the MonsterInsights frontend script (assets/js/[frontend-gtag.min.js) popped up as one of the top ten blocking scripts.

I am opening this ticket to ask that you will consider making this script non-blocking by adding either the defer or async attributes. (defer is usually preferable; use async if you want your script to execute as early as possible while still not blocking). Either one would provide performance benefits to your users - especially for slower device and bandwidth environments.

Switching on defer with WordPress 6.3+ is simple, add this one line of code after your enqueue:

wp_script_add_data( 'monsterinsights-frontend-script', 'strategy', 'defer' );

(or alternately async)

Even better would be an approach that also supported WordPress < 6.3 since I'm sure some of your users will be slow to upgrade. This gist provides a complete drop in code solution you can use; I'm also happy to provide a PR if that is helpful.

Starting by opening an issue to get your take on the suggestion - perhaps the plugin has some reason to have this be a blocking header script?

Please let me know what you think.

@ciprianimike
Copy link
Contributor

Hello @adamsilverstein , thanks for your help, we will work on this and let you know.

@adamsilverstein
Copy link
Author

👋🏼 Hey @ciprianimike,

Happy to contribute here with a PR and do some testing, however I think the repository is out of date. The last commit to this repository was from Dec, 2021 (Hi @chriscct7), perhaps a sync script has stopped working?

@ciprianimike
Copy link
Contributor

Hey @adamsilverstein while we're looking into fixing that, I want you to know we're taking a look at this internally and will have one of our developers working on it, please reach out if they have any questions

@adamsilverstein
Copy link
Author

Checking back to see if you have been able to take a look? Any luck getting the mirror syncing again?

I realize you may have some code you want to run early, you may be able to split the code up a bit though so only the critical parts are loaded from the header.

@adamsilverstein
Copy link
Author

@ciprianimike I am also happy to contribute a PR here, once you get the mirror sync working so I know I am working against a current version of the plugin.

@adamsilverstein
Copy link
Author

@ciprianimike ciprianimikeItwo proposed PRs that add async or defer - whichever works better for your case.

To add these in a way that supports older versions of WordPress, see this Gist: https://gist.github.com/adamsilverstein/ec18b67a72ff74dec12624e989e23142

@chriscct7
Copy link
Member

Hi Adam,
The team is looking into it and we'll figure something out later in the upcoming quarter for this

@adamsilverstein
Copy link
Author

Thanks, appreciate it! I'll make a note to check back in a while.

@adamsilverstein
Copy link
Author

👋🏼 Hi MonsterInsights team - checking back here to see if you have a plan to get this repository syncing soon? I'll make a note to check back in again next year! ❤️

@adamsilverstein
Copy link
Author

Hello! Checking back to see if you have any updates on this?

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