-
Notifications
You must be signed in to change notification settings - Fork 10
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
canEnqueue for 3rd party registered assets? #19
Comments
Can the team get back to me on whether you think this is a suitable addition to this package's functionality? I think I could file a PR then if it seems useful. cc @gmazzap |
Howdy, you can already enqueue Assets conditionally like following: <?php
$script = new Script('foo', 'foo.js');
$script->canEnqueue('is_checkout');
// or
$script->canEnqueue(function(): bool {
return function_exists('is_checkout') && is_checkout();
}); Same goes for |
Excellent! Is it me, or is this missing from docs https://github.com/inpsyde/assets/search?q=canEnqueue I posted this issue after reading docs, but not source. Remaining question: controlling 3rd party assets - can I take control of them with just |
After some source digging, it seems like https://github.com/inpsyde/assets/blob/master/src/BaseAsset.php could be extended to something like |
Ah now i unterstand. Currently we do not connect to anything which is "outside" of the |
True, but I'll explore some and see if I can come up with something sensible - as I could use a systemic solution to this anyway, and inpsyde/assets seems to be the highest quality asset mgmt solution currently available in the ecosystem. |
We would only take responsibility for things registered by the time of overtake operation. |
Is your feature request related to a problem? Please describe.
There are assets that need to be only conditionally loaded in specific contexts, such as payment gateway scripts not necessary anywhere outside of WooCommerce
is_checkout()
Describe the solution you'd like
New OutputFilter could accept an array of callbacks, or a boolean result to determine whether the asset should be enqueued at all.
This should also work for controlling non-
Inpsyde\Asset
dependencies. We should be able to initialize any externally enqueued handle to anInpsyde\Asset
object, then apply any OutputFilters as usual.Describe alternatives you've considered
Not sure, are there any?
Additional context
I'm looking to better control my own and various 3rd party assets enqueued to only specific contexts, to optimized asset payloads for increased page load speed.
The text was updated successfully, but these errors were encountered: