Problem/Motivation

system_page_attachments() adds the system/baselibrary to all pages and this includes all kind of styles are usually not required for the page. I think that the library should be split into several smaller libraries.

Styles that are specific to certain pages, should be attached only on those pages.

Steps to reproduce

See the performance test changes for the reduction in CSS aggregate size. It results in a reduction of approximately 2kb on visitor facing pages for both the standard profile and Umami. This should lead to further reductions when contrib switches to overriding/extending the new libraries instead of adding global rules for any of these.

Combined with the changes already made in #3432183: Move system/base component CSS to respective libraries where they exist we' re reducing the system/base size by around 7kb to around 1kb. This will be an improvement for every theme/site that hasn't explicitly removed these files from system/base in overrides already.

10.2.x 7434 bytes
11.x HEAD ~2100 bytes
11.x + remaining changes ~1100 bytes

Proposed resolution

#3432183: Move system/base component CSS to respective libraries where they exist already did some files, these are the remaining obvious ones. Note this section can be used to update the existing change record for system/base. In some cases we're moving files into existing libraries where they should have been in the first place but got overlooked, in other cases, new libraries are added and attached from their respective elements.

Open a separate issue for each distinct new library to be created.

Remaining tasks

None here, but there is more auditing of core CSS to do.

User interface changes

API changes

system-status-counter.css, system-status-report-counters.css, and system-status-report-general-info.css have been moved to a new system/status.report library.

details.module.css has been moved to the core/drupal.collapse library.

sticky-header.css has been moved to the core/drupal.tableheader library.

item-list.css has been moved to a new core/drupal.item_list library.

resize.js has been moved to a new core/drupal.resize library attached from the textarea element.

Data model changes

Release notes snippet

Issue fork drupal-2880237

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Anonymous’s picture

SchnWalter created an issue. See original summary.

lauriii’s picture

Version: 9.x-dev » 8.6.x-dev

We could try to work on this during the 8.x life cycle since we could most likely create BC layer for this in Classy.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

xamount’s picture

Wow...I did not realise this was happening after so many years of working on Drupal. I was trying to minimise unnecessary CSS on a site I was working on and I discovered all of this CSS was coming from system/base library which, as you as said, is being attached to every single page.

Here is a temporary work around, if you are are 100% sure that all of this CSS is not needed in your frontend theme:

function YOUTHEME_page_attachments_alter(array &$attachments) {
  if (in_array('system/base', $attachments['#attached']['library'])) {
    $system_base = array_search('system/base', $attachments['#attached']['library']);
    unset($attachments['#attached']['library'][$system_base]);
  }
}

Sorry but I don't have the time these days to write a patch. If I get the time, I will submit it.

anoopsingh92 made their first commit to this issue’s fork.

anoopsingh92’s picture

Yes, I am agreed with @xamount,

function YOUTHEME_page_attachments_alter(array &$attachments) {
  if (in_array('system/base', $attachments['#attached']['library'])) {
    $system_base = array_search('system/base', $attachments['#attached']['library']);
    unset($attachments['#attached']['library'][$system_base]);
  }
}

I will try to implement this preprocess function in the patch. I will provide the patch soon.
Thanks

anoopsingh92’s picture

StatusFileSize
new724 bytes

Please review this patch.

_utsavsharma’s picture

Status: Active » Needs review
_utsavsharma’s picture

StatusFileSize
new732 bytes
new701 bytes

Fixed CCF for #15.
Please review.

xamount’s picture

Status: Needs review » Needs work

Thanks for the attempt but the patches at #15 and #17 is probably not the way to go. My suggestion at #12 is just a temporary solution.

The better solution is as suggested in the issue description. That is, we need to move all the respective CSS to separate libraries and attach them to their respective templates. Once that is done, then my suggestion at #12 will no longer be needed.

xamount’s picture

Status: Needs work » Needs review

I took a stab at it and refactored most of the css that should be refactored. The remainder of css were not specific to any templates and/or were too broad and used in multiple areas of Drupal.

xamount’s picture

One important thing I noticed is that some themes (core themes included) are using libraries-override to override some of the css in the system/base library. I don't think it will break anything, but the css it will try to find will not exist.

For e.g. in claro.info.yml:

libraries-override:
  system/base:
    css:
      component:
        css/components/ajax-progress.module.css: css/components/ajax-progress.module.css
        css/components/autocomplete-loading.module.css: css/components/autocomplete-loading.module.css
        css/components/system-status-counter.css: css/components/system-status-counter.css
        css/components/system-status-report-counters.css: css/components/system-status-report-counters.css
        css/components/system-status-report-general-info.css: css/components/system-status-report-general-info.css
        css/components/tabledrag.module.css: css/components/tabledrag.css

In the above code, all of the source system-status-...css will be missing if this MR were to be merged.

What should we do about these kinds of cases?

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

MR has failures.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Category: Feature request » Task
Priority: Normal » Major

From @nod_

Seems like we could move the details css file to the drupal.collapse library too no? it's a pretty big file in claro.
Same for sticky-header.module.css that could go into drupal.tableheader maybe?

Don't think these are already included here, so adding to make sure they get included.

Also bumping priority here because this is a significant front end performance improvement for any sites that hasn't manually excluded these files itself to get the same effect.

catch changed the visibility of the branch 2880237-refactor-systembase-library to hidden.

catch’s picture

Now #3432183: Move system/base component CSS to respective libraries where they exist is in, trying to revive this one.

I've started a new MR because the approach is different. The original approach here used attach from templates, however template overrides would not get the library added so it seemed risky from a bc standpoint. Instead I've moved files between libraries where possible, or if there wasn't an appropriate library (system status et al) into a new library then using #attached in the render element.

Covered in the MR:

A new system status report library attached from the status report render element.

details.module.css moves to core/drupal.collapse

sticky-header.css moves to core/drupal.tableheader

A new core/drupal.item_list library attached from the item_list element.

A new core/drupal.resize library attached from the textarea element.

Starterkit's tabledrag styling hadn't moved in the previous MR, moved that here.

Extra things I found:

Claro's views styling should probably be a libraries-extend of one of the views UI libraries - should be a follow-up IMO mostly because I'm not sure which one is best.

edit: ResolvedLibraryDefinitionsFilesMatchTest is a lifesaver here.

catch’s picture

Component: system.module » CSS
Issue tags: +Needs change record updates

We can re-use the system/base change record we already have as long as this lands in 10.3.x. Tagging for that, and I'll add the suggested text additions to the issue summary once tests are green.

catch’s picture

Issue summary: View changes
Status: Needs work » Needs review
Related issues: +#3432183: Move system/base component CSS to respective libraries where they exist
catch’s picture

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

catch’s picture

Status: Needs work » Needs review

Rebased.

catch’s picture

Issue summary: View changes

This is a solid 2kb reduction in CSS payload for most pages now (uncompressed). We already cut out ~3.5kb in the other issue. Overall 6/7ths reduction in the size of this library, which is loaded on every page.

catch’s picture

Issue summary: View changes
smustgrave’s picture

I'm all for this, can a CR be written up?

catch’s picture

@smustgrave there's an existing CR for the previous issue at https://www.drupal.org/node/3432346

Since this issue is very similar, I was planning to copy the API changes section of this issue over to that CR once this is committed, as long as it lands in 10.3.x

nod_’s picture

Status: Needs review » Needs work

few typos in the library names

pradhumanjain2311 made their first commit to this issue’s fork.

catch’s picture

Status: Needs work » Needs review
nod_’s picture

Status: Needs review » Needs work

With the patch in the current version (using claro, aggregation off):

  1. item list style missing /admin/reports/fields, the new library is never attached anywhere
  2. tablesort indicator icon missing on claro /admin/content?title=&type=All&status=All&langcode=All&order=status&sort=asc this might need to be a follow-up, looks tricky.
  3. no style on status page /admin/reports/status
  4. There are image paths inside the CSS files that needs to be updated since the path of the css file changed.
  5. Textarea resize styles not applied /admin/structure/types
  6. Haven't found a test case for fieldgroup but that won't work either

The 2kb makes sense, there is a bunch of file that should be loaded that are not :D

kentr’s picture

container-inline.module.css could also be moved, and then attached somewhere in the container chain.

andypost’s picture

catch’s picture

Given the amount of bugs found in #40, and the amount of merge conflicts here after a few months, I think we should split this into individual issues by destination library. Will be easier to verify that way.

catch’s picture

Title: Refactor system/base library » [meta] Refactor system/base library
Category: Task » Plan
Issue summary: View changes

Switching to a meta/plan.

First issue needs review: #3511938: Move status report assets to their own library

catch’s picture

Issue summary: View changes

Next one: #3512194: Move resize CSS into its own library.

Since these all need manual testing and conflict with each other, definitely better to do library-by-library.

catch’s picture

Issue summary: View changes
catch’s picture

Issue summary: View changes

Added #3512262: Move details.module.css to the collapse library because that also shouldn't conflict hopefully.

From the original MR here, this leaves:

Sticky tableheaders - already done in #3439580: Make drupal.tableheader only use CSS for sticky table headers

Tablesort - needs work issue already at #3432244: Split tablesort.module.css out to its own library and attach it via tablesort

item-list - @todo.

catch’s picture

Issue summary: View changes
Status: Needs work » Active
catch’s picture

That's everything split out to its own issue now.

Of the remaining files:

clearfix.module.css - class is used by multiple core demplates.
align.module.css - used various places in core, but we should remove the views duplicates: #3436855: Remove the views-align-* CSS classes
container-line.module.css - used in lots of places.
hidden.module.css - used a lot
js.module.css - used a lot
nowrap.module.css - can't see where this is used at all, maybe we can deprecate/drop it.
position-container.module.css - one usage in claro, could maybe be factored out.
reset-appearance.module.css - one usage in claro, could be factored out.

catch’s picture

Issue summary: View changes
catch’s picture

Issue summary: View changes
catch’s picture

Issue summary: View changes
catch’s picture

Issue summary: View changes
catch’s picture

Issue summary: View changes

Getting close to 1kb of CSS once remaining issues are in, this is down from 7kb originally.

catch’s picture

Issue summary: View changes
catch’s picture

Issue summary: View changes
klemendev’s picture

Getting close to 1kb of CSS once remaining issues are in, this is down from 7kb originally.

That is amazing. Nice work!

catch’s picture

Issue summary: View changes
catch’s picture

Issue summary: View changes
catch’s picture

Issue summary: View changes

Opened #3515090: [meta] Olivero page weight improvements for some similar issues in Olivero and added a couple more child issues here.

catch’s picture

Issue tags: -Needs issue summary update +11.2.0 release highights
quietone’s picture

Issue tags: -11.2.0 release highights +11.2.0 release highlights
catch’s picture

Issue summary: View changes

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.