XF 2.3 Using lazy handler loader & full JS

Kirby

Well-known member
Either I am missing smth. or using lazy loaded handlers & full JS is kinda complicated:

HTML:
<xf:if is="$xf.development && $xf.fullJs">
    <xf:js addon="vendorprefix/addonid" src="vendorprefix/addonid/file.js" />
<xf:else />
    <xf:js>XF.LazyHandlerLoader.register('js/vendorprefix/addonid/file.min.js', 'handlername', 'click');</xf:js>
</xf:if>

Is there a simpler way to achieve this?

If not:
Could we have smth. simpler like
HTML:
<xf:js addon="vendorprefix/addonid" src="vendorprefix/addonid/file.js" min="1" lazy="handlername:click" />
?
 
Last edited:
To be honest the lazy-loader was originally written so we could split out lesser-used handlers that were formerly included on every page without breaking backwards-compatibility for styles and add-ons. Otherwise we would have just added <xf:js> tags to include the files explicitly where necessary. It wasn't really written with other use cases or third-party usage in mind.
 
Otherwise we would have just added <xf:js> tags to include the files explicitly where necessary.
Hmm ... but that wouldn't be as efficient as it is right now.

Assuming i've got a complex click handler that is available on many pages but is used really seldom it would be a waste of resources to always include that; having it only loaded when really required seems ideal to me?
 
Hmm ... but that wouldn't be as efficient as it is right now.
I think it would be roughly the same in most cases. If the elements or their data-xf-init/data-xf-{event} attributes are conditional, the <xf:js> tag can usually be conditional as well. The lazy-loaded event handlers are still loaded with the page, regardless of whether or not the events are actually triggered.

I do think there's room to improve the handler system more broadly with better support for on-demand loading (among other things), and I've even written a few proof-of-concepts, but the existing lazy-loading mechanism was written for a rather narrow use case.
 
Top Bottom