It would be great to be able to not activate it in admin path - if eg some javascript is loaded for both admin path and regular pages but only critical for admin

CommentFileSizeAuthor
#4 StrategiesOrderSubscriber.txt1.07 KBvdsh

Comments

vdsh created an issue. See original summary.

vdsh’s picture

I think the use case is broader than that: we should be able to optimize differently depending on contexts.

Eg: a leaflet map could be critical on one node type and not so important on another one.

To achieve this, we would need to change configuration from simple configuration to configuration entities and create a "context selection" as well as an associated "context configuration"

That way we can have a default configuration for all the site or finetune it per context (or a mix of both: default configuration for most pages but on a specific page a different configuration)

vdsh’s picture

Status: Active » Fixed

This is now possible with latest 2.0.x dev (and will be available in release 2.0). You can define your strategies and then use an event subscriber to the StrategiesOrderAlter::EVENT_NAME event to disable some strategy on admin path or to use a specific one.

...

/**
   * {@inheritdoc}
   *
   * @return array
   *   The event names to listen for, and the methods that should be executed.
   */
  public static function getSubscribedEvents() {
    return [
      StrategiesOrderAlter::EVENT_NAME => 'updateOrder',
    ];
  }

  /**
   * Update strategies order.
   *
   * @param \Drupal\libraries_delay_load\Event\StrategiesOrderAlter $event
   *   The event.
   */
  public function updateOrder(StrategiesOrderAlter $event) {
    // Do not display on admin.
    if (\Drupal::service('router.admin_context')->isAdminRoute()) {
      $event->setStrategies([]);
      return;
    }
    // Alternatively, select specific strategy on admin.
    if (\Drupal::service('router.admin_context')->isAdminRoute()) {
      $event->setStrategies(['admin_strategy']);
      return;
    }
  }
...
vdsh’s picture

StatusFileSize
new1.07 KB

Attached is the full event subscriber example as a txt file

vdsh’s picture

With the 2.0.1 version, you can also use Rules to do this, see #3139144: Prioritize strategies with Rules

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.