Hello,

Similar to what was done here : https://www.drupal.org/node/2671148 I would like to know if there is currently a good option to disable loadCSS for specific roles. And if you would think that is an interesting thing.

It would be a good thing on my project since enabling loadCSS breaks admin menu and other admin things that might be rendered on the page, and are not things that I want to put in the criticalCSS for these users.

I could provide a patch for this. I will try to make that here in the next hours. But if there is already an option to do this I would like to know;p

Best regards
Joao Garin

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joaogarin created an issue. See original summary.

joaogarin’s picture

Here goes a little patch for this. Would be great to get some feedback on it;) Definitely need some way of doing this.

  • mikeytown2 committed a0a53c6 on 7.x-2.x
    Issue #2722443 by mikeytown2, joaogarin: Allow for loadCSS js to be...
mikeytown2’s picture

What about something that uses hooks instead of the UI. I've committed the attached patch. Example of it in action. This is essentially what you need; disable loadCSS if an unaccounted for css file is there.

/**
 * Implements hook_advagg_mod_get_lists_alter().
 */
function CUSTOM_advagg_mod_get_lists_alter(&$lists, $js, $css) {
  if (!empty($lists[10])) {
    $no_defer_css = FALSE;
    foreach ($css as $key => $value) {
      if (strpos($key, '/admin_menu/admin_menu.css') !== FALSE) {
        $no_defer_css = TRUE;
        break;
      }
    }
    if ($no_defer_css === TRUE) {
      $lists[10] = 0;
    }
  }
}
joaogarin’s picture

That also looks like a really good solution! ;)

joaogarin’s picture

I am going to try it out but it actually sounds like an even better option. maybe both are actually useful for some edge cases but either one will work for my case at least.

Sounds very good.

joaogarin’s picture

I am trying the patch but the $css parameter is empty in my alter hook.

  • mikeytown2 committed 55d46dd on 7.x-2.x
    Issue #2722443 by mikeytown2: Fix issue with static inside of...
mikeytown2’s picture

Looks like an issue with the static cache; this should handle that situation.

mikeytown2’s picture

Is this good enough for you or does something else need to be done?

joaogarin’s picture

From what i see this is already in the 7.x version? I just tested works nicely;) thanks!!

mikeytown2’s picture

Status: Active » Fixed

Going to mark this as fixed

Status: Fixed » Closed (fixed)

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