I'm on a bit of an efficiency drive. To this end, I would like to check all the scripts and CSS that get enqueued on my multisite setup. I plan to check that they are offloaded to public CDNs if available or some other private static site if I have set that up, while also ensuring there are no duplicates.
Where I am currently stuck (aside from wondering if the extra work actually will save load times at all) is what hook I can use to make sure all the enqueing is done when my script kicks in.
What hook or filter should I use for this purpose?
(Feel free to educate me and any future searchers about anything else I/we should know when attempting this).
I'm on a bit of an efficiency drive. To this end, I would like to check all the scripts and CSS that get enqueued on my multisite setup. I plan to check that they are offloaded to public CDNs if available or some other private static site if I have set that up, while also ensuring there are no duplicates.
Where I am currently stuck (aside from wondering if the extra work actually will save load times at all) is what hook I can use to make sure all the enqueing is done when my script kicks in.
What hook or filter should I use for this purpose?
(Feel free to educate me and any future searchers about anything else I/we should know when attempting this).
Share Improve this question asked Sep 4, 2019 at 20:47 Matthew Brown aka Lord MattMatthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges1 Answer
Reset to default 0In terms of the basics, I have learned that there are two actions to hook - wp_print_scripts
and wp_print_styles
which I understand are called just before they are then added to the header.
add_action( 'wp_print_scripts', 'my_list_scripts' );
function my_list_scripts() {
global $wp_scripts;
$enqueued_scripts = array();
foreach( $wp_scripts->queue as $handle ) {
// do something clever
}
}
add_action( 'wp_print_styles', 'my_list_styles' );
function my_list_styles() {
global $wp_styles;
$enqueued_styles = array();
foreach( $wp_styles->queue as $handle ) {
// do something clever
}
}