Optimization: load CSS when shortcode is used only
-
The youtube-playlist-thumbs.css is loaded irrespective of whether the plugin’s shortcode is loaded. Granted, the file is not very big. But when the plugin is used on 1/1000 pages only (like in our case) the extra network requests are hard to justify.
I realize that WordPress’ API makes optimization of CSS loading a bit difficult. See e.g. https://wordpress.stackexchange.com/questions/108444/how-to-add-stylesheets-only-to-pages-with-specific-shortcode for a discussion. I’d see two options:
1.) Split the wp_enqueue_style() call into wp_register_style() and wp_enqueue_style() whereas the latter would be called in the shortcode function only. Whether all browsers can deal with the css link outside of the HTML page head I don’t know.
2.) Inline with CSS as a <style> element when the shortcode function outputs the YouTube frame. The youtube-playlist-thumbs.css may be insertable at runtime via an ‘include’ statement.
Thanks.
The topic ‘Optimization: load CSS when shortcode is used only’ is closed to new replies.