Skip to main content

I've been working on a problem where a font and image tag aren't appearing on the front end of my website. I found that if I disable CSS aggregation, the YouTube play button symbol and overlay will appear. However, this slows down the page speed.

How to leverage CSS aggregation but set specific files to be excluded?

I'm wondering how to leverage CSS aggregation but exclude specific files. Here's an example of what my theme libraries file looks like:

global-styling:
  version: 1.x
  header: true
  css:
    base:
      assets/dist/css/tailwind.css: {}
      assets/dist/css/style.css: {}
      assets/dist/css/responsive.css: {}
    theme:
      assets/dist/css/editor.css: {}
      assets/dist/css/layout.css: {}
      assets/dist/css/navigation.css: {}
      assets/dist/css/headers.css: {}
      assets/dist/css/button-link.css: {}
      assets/dist/css/misc.css: {}
      assets/dist/css/homepage.css: {}
      assets/dist/css/forms.css: {}
      assets/dist/css/vendors.css: {}
  dependencies:
    - core/jquery
    - core/drupal
    - core/jquery.once
    - core/drupal.ajax
    - core/views.ajax

 

To exclude a CSS file, you need to add { preprocess: false } against the relevant file.  To exclude misc.css file it will look as follows:

global-styling:
  version: 1.x
  header: true
  css:
    base:
      assets/dist/css/tailwind.css: {}
      assets/dist/css/style.css: {}
      assets/dist/css/responsive.css: {}
    theme:
      assets/dist/css/editor.css: {}
      assets/dist/css/layout.css: {}
      assets/dist/css/navigation.css: {}
      assets/dist/css/headers.css: {}
      assets/dist/css/button-link.css: {}
      assets/dist/css/misc.css: { preprocess: false }
      assets/dist/css/homepage.css: {}
      assets/dist/css/forms.css: {}
      assets/dist/css/vendors.css: {}
  dependencies:
    - core/jquery
    - core/drupal
    - core/jquery.once
    - core/drupal.ajax
    - core/views.ajax

 

 

Related articles

Andrew Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...