How to remove the global library from specific page ?

I want to rearrange java script files.


You need to implement hook_page_attachments_alter().


Yes, it's very simple to use the Hook_page_attarchment_alter() Please see the following code it may help you.

    function modulename_page_attachments_alter(array &$attachments) {

    // Conditionally remove an asset.
    $current_path = \Drupal::service('path.current')->getPath();
    $result = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);
    if ($result == "/<url slug>" ){
      if (in_array('<theme name>/global-styling', $attachments['#attached']['library'])) {
        $index = array_search('<theme name>/global-styling', $attachments['#attached']['library']);


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.