Proposed changes to wp enqueueing and shortcode handling
|Reported by:||Jester831||Owned by:||Jester831|
|Severity:||major||Keywords:||dev-feedback needs-patch needs-codex|
Currently, the only way for a programmer to avoid loading their scripts/css on every page is to either peek through the_content() for their shortcode and enqueue accordingly, or to use their shortcode handler to set a boolean for doing a conditional script print after partially loading a page. While this is certainly feasible, it's largely unused and the majority of plugins overload css and js unnecessarily.
I propose that instead of operating under the expectation that all programmers do this, we instead implement a mechanism to do this solely through wp_enqueue_script and wp_enqueue_style.
This can be achieved by storing a list of used shortcode tags within a pages meta, likely while saving a post or page, that can later be used as a conditional check with, among others, wp_enqueue_script and wp_enqueue_style.
A new optional parameter would be then added to wp_enqueue_script and wp_enqueue_style that would check said meta, or potentially other meta, and conditionally load, without the requirement of any further coding.