-
-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add asset priority & use AssetMaker for global backend assets #1022
Conversation
The "priority" property should probably be called "order" and have a default value of 500, as that is what the backend menu and permissions registration already does. The current implementation makes these global assets a responsibility of the skin, so I'm not sure how I feel about them being included in the base controller class; thereby forcing them to be included in every single backend skin. |
Co-authored-by: Luke Towers <[email protected]>
@LukeTowers we can add a parameter to the Skin class that defines whether to load the global assets or not - thereby making it the responsibility of the skin to load all necessary assets? Alternatively, the skin itself could be the class that provides the global assets, although this might take some refactoring for the base skin. |
Hmm, I think I have a better idea, let's just add in those assets dynamically in the layout file itself since that's where they're used anyways. Different layouts have different global assets, so I don't really like having it be defined in the controller or the skin. |
So basically just can this PR because that's what was done originally? |
The point of this PR would be to pass those assets through the AssetMaker trait (instead of manually rendering them as script / style tags) so that their attributes can be controlled through the event system (thus removing the cfasync attribute from the core as you wanted and moving it into the cloudflare specific plugin). |
@bennothommo idea was along the lines of $this->addAssets([...]) in the layout files instead of directly rendering the asset tags; thus forcing them to go through the AssetMaker trait and associated events. Any thoughts? |
@LukeTowers are we still going to implement ordering / prioritising with that? I can't quite recall the reason I did this PR (might've had something to do with the backend skinning or the widgets). I imagine it was to enforce some scripts / styles loading before other global scripts / styles, but it might be misleading if the assets are placed directly in the layouts or partials. I think we'll have difficulty using the |
Yes, I'm fine with the ordering / prioritization changes staying. I don't think we'll have to do any extra passes on the layout because we can dynamically add them exactly where they're being added right now, which is right before the call to makeAssets(), so I don't see any reason why it wouldn't work. |
The preload definition has changed somewhat since this was last looked at (see https://web.dev/articles/fetch-priority#history; ex. fetchpriority instead of priority). Additionally, the MDN article on rel=preload (https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel/preload#the_basics) makes a good point that adding preloads for resources immediately before actually loading them doesn't actually help ("the browser probably discovers the <link rel="stylesheet"> and <script> elements in the same chunk of HTML as the preloads"), but should instead be used for resources loaded much later on in the page lifecycle: > the benefits can be seen much more clearly the later resources are discovered and the larger they are. For example: > Resources that are pointed to from inside CSS, like fonts or images. > Resources that JavaScript can request, like imported scripts. For this reason we'll remove the initial stuff we have related to fetchpriority and preloading. If we would like to implement it in the future, I would recommend that we take more of an approach of having a separate categorization for preloads, i.e. more along the lines of addPreload(). Potentially at that point we could do things like advance scanning of the assets added by addCss / addJs to dynamically generate some useful preloads, but for now this is not required by any active projects so we'll table it for now.
Theoretically we could have some helper methods / a standard interface in the base Backend Skin class to handle this, which might also simplify the TailwindUI skin, but for now we just can't have them being defined in the controller. Also fixed a small oversight on the type hints for addCss / addJs / addRss
This PR changes the global backend assets that were originally specified directly in the "head" template for the Backend, and uses the
AssetMaker
to load them instead. This should allow people the ability to manipulate the assets if need be through events.To ensure that the global assets are loaded first before all others, I have also introduced a
priority
order
value for assets. It may be specified by providing the second argument foraddJs()
,addCss()
, etc. as an array and populating it with the following:The default order for all assets is
500
.CSS and JS assets can also be set to be preloaded by adding a
preload
value set totrue
. This will ensure that the appropriatepreload
tag is included with the asset.