Support » Plugin: Better WordPress Minify » enqueuing scripts on a hook callback of wp_enqueue_scripts

  • I think I’ve found why Revolution Slider doesn’t play nice with your plugin, but I wanted to run this by you to make sure I know what the hell I’m talking about.

    EDIT: IGNORE ALL THIS. SEE COMMENT BELOW

    It seems that Revolution Slider initializes itself and does all of its wp_enqueue_* within a hook for wp_enqueue_scripts. In other words:

    do_action( 'wp_enqueue_scripts', 'add_plugin_x_scripts' );

    I’m betting that you do your minify string magic in the same or an earlier hook. Am I right? And wouldn’t that cause a sequence issue or race condition where the other plugin may still get its script or style enqueued, but only after you’ve already done all your modifications in BWP?

    END EDIT

    I realize that this is not your problem. I’m really just trying to figure out what to recommend to RevSlider’s authors to make it more compatible with minifcation plugins in general. 🙂

    https://wordpress.org/plugins/bwp-minify/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter James Revillini

    (@jrevillini)

    OK I found out what the problem was. There are two issues, actually.

    First issue: when the Revolution Slider is set to output its scripts to the HEAD tag, it enqueues the scripts. When it is set to output to the footer, they are just echoing <script> tags. That’s obviously not going to work. So I fixed their code so it enqueues even in the footer. But there’s another problem that you may be able to address in your plugin.

    Second issue: they are adding querystring parameters to THEIR scripts and styles and not using the version parameter to do so. See code samples below:

    wp_enqueue_script($handle, self::$url_plugin .$folder."/".$scriptName.".js?rev=". GlobalsRevSlider::SLIDER_REVISION, $waitfor, $footer);

    The ?rev=". GlobalsRevSlider::SLIDER_REVISION bit is causing it to output script tags like this:

    <script type='text/javascript' src='http://cdn3.vandertech.com/wp-content/plugins/revslider/rs-plugin/js/jquery.themepunch.plugins.min.js?rev=4.1.4&ver=1'>

    Your script doesn’t handle the & – it skips rewriting strings like this. If I alter their code to look like the following, it works:

    wp_enqueue_script($handle, self::$url_plugin .$folder."/".$scriptName.".js", $waitfor, $footer);

    Thread Starter James Revillini

    (@jrevillini)

    Plugin Author Khang Minh

    (@oddoneout)

    Don’t worry about race condition, BWP Minify should be able to capture all the enqueued scripts, especially version 1.3.0-beta.

    If I remember correctly WordPress strip the ?rev part from src when scripts are enqueued, so it should not be there. Can you try with 1.3.0-beta to see if that’s still an issue?

    Thread Starter James Revillini

    (@jrevillini)

    Unfortunately, I don’t have time to try out the beta software, and I’ve worked around the ?rev issue by modifying the RevSlider plugin directly. I’m told the newest version of that plugin enqueues in a more standard way. The current version definitely allows the ?rev part to come through the the javascript src attribute.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘enqueuing scripts on a hook callback of wp_enqueue_scripts’ is closed to new replies.