Skip to content

[FEATURE] - Better asset loading #536

@dingo-d

Description

@dingo-d

So, while thinking about how to improve performance on my company's site, an idea popped up in my mind.

Instead of immediately enqueueing all the assets all the time from the plugin (or the add-on), you enqueue the styles and scripts only when somebody uses the form block (revolutionary I know 😂 but should be doable).

The POC would be like this (2 ways):

1st approach

In the assets classes only register block/frontend scripts and styles, and then create a helper method that will enqueue those scripts/styles that can be used inside the block's PHP file like:

...
EnqueueHelper::loadScriptsAndStyles();
// rest of the block code goes here

2nd approach

Alternatively, one could see what action hook executes during the render phase of the block, and hook there to execute the wp_enqueue_script/style WP functions (gives you cleaner code, less static helpers and manual addition to blocks).

This could be used in the libs as well. There we would need to separate scripts/styles for every block, and then based on the block load only their scripts/styles (handles would be dynamic based on block name), which would then lower the size of the application* files, and load only those scripts/styles that are actually used on the current page.

These files would be smaller, and HTTP2 is already favouring loading multiple smaller files than one big file anyhow, so that would be a performance win.

Just a food for thought...

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions