Closed boonebgorges closed 9 months ago
I've got a version of this up and running. I made the primary change at the level of Intraxia\Jaxion\Assets\Register
. Instead of register()
building an internal queue, and then using that queue to enqueue scripts based on the 'condition' argument, register()
now calls wp_register_script()
. Assets are then enqueued on an as-needed basis.
I've made very little attempt at this point to pick apart unneeded dependency chains. That being said, I can already see a decrease of 3-5 scripts/styles being added by PF on most pages in the Dashboard. This includes assets that were needlessly loaded globally, as well as those that were loaded on all PF pages but are only needed in a handful of places. I'll continue to clean these areas up as it's convenient to do so.
I'll close this ticket for now, but continue in future versions to look for places where I can improve the relationship between dependent scripts.
PressForward currently loads many of its scripts and styles using its
AssetsProvider
system, which internally uses theRegister
toolset in Jaxion. The Jaxion system, and PF's technique for leveraging it, have some limitations:wp_register_script()
) separately from their enqueuing (wp_enqueue_script()
). Instead, Jaxion expects a'condition'
callback that returnstrue
when the script should appear, andfalse
when it shouldn't. This system requires significant foresight and some potentially complex logic for determining when to returntrue
from'condition'
. PressForward simply errs on the side of loading everything almost everywhere, which is bad for performance.'condition'
returnstrue
, while B's'condition'
returnsfalse
; A therefore unexpectedly does not load. As such, this system partly overrides the sanity checks built into WP's dependency system.The current system feels overengineered, raising the bar for developer experience (it's harder to reason about and keep track of), which leads to sacrifices that reduce performance (like PF's just-load-everything strategy).
I'd like to move toward a system that works like this:
Core\Providers\AssetsProvider
. This is in the spirit of the current setup. An alternative would be to allow individual components to be responsible for registering their own assets. I don't think it's super important either way. The critical thing is that, instead of maintaining our own registry as Jaxion does, we pass everything immediately towp_register_script()
orwp_register_style()
.wp_enqueue_style()
, but this would an exception to the rule.