Please optimize the plugins script loading
-
There is no need to load all the heavy scripts on every WordPress page. You can call
wp_enqueue_script
at any time b4 the footer scripts are printed. I guess there is no need to load the scripts in the<head>
.To do this, remove this line from the
WPSC_Frontend
class:add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) );
And then you load the scripts only when the shortcodes are actually used on pages. You can call WPSC_Frontend::load_scripts() inside all the
layout
methods for all the shortcodes where the scripts are needed.final class WPSC_Shortcode_One { // ... /** * "supportcandy" shortcode layout * * @param array $attrs - Shortcode attributes. * @return string */ public static function layout( $attrs ) { \WPSC_Frontend::load_scripts();
I would appreciate if you do this and test it, it seems to work fine for me. That way, people sites are not polluted with all these scripts that are only needed for the support page(s). Especially because these are quite a lot and they are typically backend scripts.
Great plugin btw, thanks.
- The topic ‘Please optimize the plugins script loading’ is closed to new replies.