Plugin loading unnecessary js on frontend?
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
- Install version 3.17.0 of the plugin.
- 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.
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.
Thank you, appreciate it! Always looking for ways to minimize js waste on the front end for speedy load times.
Hello! Here's a summary of our findings:
General timeline
- The
hooks.jsscript was introduced in wp-parsely 3.2 (released March 29, 2022) through this PR. This is a result of us including the@wordpress/hookspackage as a dependency in ourloader.jsscript, so JS hooks can be used as mentioned in the PR. - In this and some subsequent versions,
hooks.jsneeded to inject a polyfill script. - When we released wp-parsely 3.11,
hooks.jsstarted injectingi18n.jsinstead 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.