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.
- #3512285: Split item-list.module.css out to its own library
#3512262: Move details.module.css to the collapse library#3512284: Remove details.css since it is no longer needed- #3512236: Move fieldgroup CSS to its own library
- #3512194: Move resize CSS into its own library
- #3511938: Move status report assets to their own library
- #3432244: Split tablesort.module.css out to its own library and attach it via tablesort
- #3512404: Move reset-appearance.module.css to its own library
- #3514745: Remove nowrap.module.css
- #3514748: Remove legacy browser support from js.module.css
- #3514853: Remove position-container.module.css from system/base
- #2417111: Replace container-inline with form--inline to display forms horizontally.
- #3436855: Remove the views-align-* CSS classes
- #3515097: [PP-1] Audit use of the clearfix class
- #3565297: Move 'display link' CSS to its own views library
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
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 2880237-nr-bot.txt | 90 bytes | needs-review-queue-bot |
Issue fork drupal-2880237
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
Comment #1
Anonymous (not verified) commentedSchnWalter created an issue. See original summary.
Comment #2
lauriiiWe could try to work on this during the 8.x life cycle since we could most likely create BC layer for this in Classy.
Comment #12
xamountWow...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:
Sorry but I don't have the time these days to write a patch. If I get the time, I will submit it.
Comment #14
anoopsingh92Yes, I am agreed with @xamount,
I will try to implement this preprocess function in the patch. I will provide the patch soon.
Thanks
Comment #15
anoopsingh92Please review this patch.
Comment #16
_utsavsharma commentedComment #17
_utsavsharma commentedFixed CCF for #15.
Please review.
Comment #18
xamountThanks 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.
Comment #20
xamountI 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.
Comment #21
xamountOne 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:
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?
Comment #22
smustgrave commentedMR has failures.
Comment #24
catchFrom @nod_
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.
Comment #27
catchNow #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:
ResolvedLibraryDefinitionsFilesMatchTestis a lifesaver here.Comment #28
catchWe 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.
Comment #29
catchComment #30
catchComment #31
needs-review-queue-bot commentedThe 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.
Comment #32
catchRebased.
Comment #33
catchThis 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.
Comment #34
catchComment #35
smustgrave commentedI'm all for this, can a CR be written up?
Comment #36
catch@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
Comment #37
nod_few typos in the library names
Comment #39
catchComment #40
nod_With the patch in the current version (using claro, aggregation off):
/admin/reports/fields, the new library is never attached anywhere/admin/content?title=&type=All&status=All&langcode=All&order=status&sort=ascthis might need to be a follow-up, looks tricky./admin/reports/status/admin/structure/typesThe 2kb makes sense, there is a bunch of file that should be loaded that are not :D
Comment #41
kentr commentedcontainer-inline.module.csscould also be moved, and then attached somewhere in thecontainerchain.Comment #42
andypostComment #43
catchGiven 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.
Comment #44
catchSwitching to a meta/plan.
First issue needs review: #3511938: Move status report assets to their own library
Comment #45
catchNext 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.
Comment #46
catch#3512236: Move fieldgroup CSS to its own library theoretically won't conflict with #3512194: Move resize CSS into its own library so added that too.
Comment #47
catchAdded #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.
Comment #48
catchComment #49
catchThat'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.
Comment #50
catchComment #51
catchComment #52
catchComment #53
catchComment #54
catchGetting close to 1kb of CSS once remaining issues are in, this is down from 7kb originally.
Comment #55
catchComment #56
catchComment #57
klemendev commentedThat is amazing. Nice work!
Comment #58
catchComment #59
catchComment #60
catchOpened #3515090: [meta] Olivero page weight improvements for some similar issues in Olivero and added a couple more child issues here.
Comment #61
catchComment #62
quietone commentedComment #63
catchDifferent file, same genre: #3565297: Move 'display link' CSS to its own views library.