Postponed on #2998451: Toolbar tray rendering can result "flickering" resizing of content area to accommodate open trays
Problem/Motivation
#2998451: Toolbar tray rendering can result "flickering" resizing of content area to accommodate open trays👈 this issue included the addition of inline JavaScript to <head>
so it could load before anything on the page was rendered. This resulted in a less visually jarring toolbar initialization.
The JS is currently added via toolbar_page_attachments()
, adding a script tag to $page['#attached']['html_head']
. Unlike most Drupal JavaScript, the JS code is not in a dedicated file, but created as a HEREDOC variable. It's not the most elegant DX, but it got the job done. We'd like to find a better approach.
Some things that were tried:
- Having this JS be part of a library with
header: true
, which was decided against as it adds an additional JS request, even when assets are aggregated - Having the JS be in a dedicated file, but not part of a library. PHP would load the file in
toolbar_page_attachments()
, write the contents to a string, which would ultimately become the content of the newly added script tag. This was decided against as it would result in loading a file from the filesystem on every request. This could potentially be addressed by usingFileCacheFactory
, but best explored in a dedicated issue such as this instead of blocking the anti-flicker enhancements provided by #2998451