wp-parsely icon indicating copy to clipboard operation
wp-parsely copied to clipboard

Plugin loading unnecessary js on frontend?

Open nikkoi opened this issue 1 year ago • 3 comments

Describe the bug

I noticed that at least as of version 3.17.0 of the plugin, it loads hooks.min.js and i18n.min.js on the front end of wordpress. I can't see why these js files would be necessary for it to run, and if they are, can you please explain how they weren't needed before.

To Reproduce

  1. Install version 3.17.0 of the plugin.
  2. See the files hooks.min.js and i18n.min.js load on the front end, when logged out.

Expected behavior

I assume this files are only needed when logged in in wp-admin

Environment

Plugin version 3.17.0 WP version 6.7.1

Additional context

Loading unnecessary JS slows the web page down.

nikkoi avatar Nov 27 '24 10:11 nikkoi

Hello and thank you for reporting this.

We will investigate this within this week or the next, and we'll get back to you as soon as possible.

acicovic avatar Dec 04 '24 09:12 acicovic

Thank you, appreciate it! Always looking for ways to minimize js waste on the front end for speedy load times.

nikkoi avatar Dec 04 '24 11:12 nikkoi

Hello! Here's a summary of our findings:

General timeline

  1. The hooks.js script was introduced in wp-parsely 3.2 (released March 29, 2022) through this PR. This is a result of us including the @wordpress/hooks package as a dependency in our loader.js script, so JS hooks can be used as mentioned in the PR.
  2. In this and some subsequent versions, hooks.js needed to inject a polyfill script.
  3. When we released wp-parsely 3.11, hooks.js started injecting i18n.js instead of the polyfill.

Are these scripts needed?

loader.js is needed to disable autotracking when the "Disable Autotracking" setting is on, as well as when the website uses wp-parsely JS hooks. These are operations that take place on the front-end. hooks.js and i18n.js are loaded as dependencies of loader.js.

Considerations for the future

We could attempt to decouple the "Disable Autotracking" setting from the loader, and give a setting to disable JS hooks when they aren't being used. This would prevent the extra scripts from being included. This is a possible pathway, but it hasn't been tested.

acicovic avatar Dec 10 '24 07:12 acicovic