WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 3 years ago

#16585 closed enhancement (wontfix)

Proposed changes to wp enqueueing and shortcode handling

Reported by: Jester831 Owned by: Jester831
Milestone: Priority: normal
Severity: major Version: 3.1
Component: General Keywords: dev-feedback needs-patch needs-codex
Focuses: Cc:

Description

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.

Change History (3)

comment:1 kawauso3 years ago

  • Cc otterish@… added

comment:2 scribu3 years ago

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.

Big -1. As described in IRC:

(01:40:45 AM) scribu: scenario: you make a simple shortcode that doesn't need additional css/js and you release it as a plugin
(01:41:21 AM) scribu: afterwards, you make it fancier and now you do need a some additional css/js
(01:41:36 AM) scribu: you release the updated version of the plugin and the user updates
(01:41:52 AM) scribu: but wait, the user already has posts that use the previous version of the shortcode
(01:41:58 AM) scribu: what happens then?

comment:3 scribu3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to wontfix
  • Status changed from new to closed

We had a lengthy discussion in IRC, which can be summarised as follows:

  • a solution for Core would need to avoid DB writes on the front-end and bulk re-processing of posts on plugin activation (we couldn't find said solution)
  • most shortcodes shouldn't have heavy JS/CSS anyway, so it shouldn't be such a big deal if they're loaded on all pages
Note: See TracTickets for help on using tickets.