WordPress.org

Ready to get started?Download WordPress

Forums

Better WordPress Minify
Idea about priority (5 posts)

  1. tzdk
    Member
    Posted 2 years ago #

    If someone go all manual with bwp_minify_allowed_styles and ditto scripts I think most would want the bundle to load as early as possible. But as it is it will be the opposite because of priority 100. Could that be made configurable other than changing value manually?

    Thinking of init snippets and such that tends to work best if loaded after everything else. These items are not always possible to control so not easy to reposition.

    Kind of conflicts with auto-mode I guess where as late as possible fits better.

    Brilliant plugin and even more brilliant if I am wrong ;)

    http://wordpress.org/extend/plugins/bwp-minify/

  2. Khang Minh
    Member
    Plugin Author

    Posted 2 years ago #

    Hmm maybe if you have a real example it would help me understand the issue better ;-). Thanks.

  3. tzdk
    Member
    Posted 2 years ago #

    Ok, try Tippy http://wordpress.org/extend/plugins/tippy/ lovely plugin.

    It works like this out of the box:
    1. 1 JS and 1 CSS file in head
    2. Init snippet based on settings below them, and especially JS file!

    With Better Minify this order is kept if nothing is touched but just moving "Tippy" to footer will render snippet useless as it depends on main file to be loaded before.

    This might be obvious but lets say I do it manually like this

    add_filter('bwp_minify_allowed_scripts', 'my_allowed_scripts');
    function my_allowed_scripts() {
       return array(
       'Tippy'                // manually placed in footer
        );
       return;
    }

    And since I know snippet from plugin now wont work I move that too:

    /* - [ TIPPY FIX ] - */
    remove_action('wp_head', 'tippy_load_settings');
    add_action('wp_footer', 'tippy_load_settings_new', 120); // 120 so it comes after BWP
    function tippy_load_settings_new() {
    	if (get_option('tippy_fadeTip', 'fade') == "fade")
    	{
    		$tippyFadeRate = 300;
    	} else {
    		$tippyFadeRate = 0;
    	}
    	echo '
    		<script type="text/javascript">
    			Tippy.initialize({
    blah, blah
    			});
    		</script>
    	';
    }

    Then it will STILL come before BWP bundle because you fire that off with a priority of 100, hence the added 120.

    From class-bwp-minify.php

    add_action('wp_footer', array($this, 'print_footer_scripts'), 100);

    So that 100 number could be nifty to manipulate :) More so because not all plugins allow this fiddling so not really anything to do other than changing number manually.

    Or is there any action hook that will always come after "wp_footer"?

    Not worlds biggest problem and may be nothing to do but if you have mentioned how a JS file can be tied to initialization snippets in FAQ I think you should. If not BWP will be blamed, that is guranteed :)

  4. Khang Minh
    Member
    Plugin Author

    Posted 2 years ago #

    First of all, thank you for such a detailed example. Couple of things:

    So does this:

    add_action('wp_footer', 'tippy_load_settings_new', 120); // 120 so it comes after BWP

    work? This is in your theme's functions.php right?

    Not worlds biggest problem and may be nothing to do but if you have mentioned how a JS file can be tied to initialization snippets in FAQ I think you should. If not BWP will be blamed, that is guranteed :)

    What kind of FAQ would you expect?

  5. tzdk
    Member
    Posted 2 years ago #

    Yes it does work as order of what plugin expect is kept.

    I was just thinking that the fact plugins can add initialization snippets all over the place might not be obvious to everyone. And both your plugin and users might break that and render output crap.

    This is really obvious if source code is checked before fiddling - and we all to that... Your plugin make it clear enqueue┬┤ing is all that counts and hence nothing can break, or should not, but you cant control what plugin spit out. So to cover your butt and may be warn a bit this might be relevant for a FAQ or sticky.

    Btw, I see you will add feature for showing handles. Up to now I have used a snippet from WPEngineer, tuned by Stackoverflow and shined up by me - I added headlines and line breaks, heh. Links in code. Try check Background Manager plugin http://wordpress.org/extend/plugins/background-manager/ for why this can stop tears. Nearly broke me. Usually easy enough to find those handles though, still nifty.

    I have some respect for this minifying stuff. Why I prefer to do most manually and so I need handles, lots!

    Also I have some doubts about minifying other file than those used on all pages. Your plugin respects conditional powers but that also means a site can get loads and loads of minifed "sets". Good for caching = nope. Like starting over with a new unique bundle, again and again. In theory each page could have own set of JS and CSS. Feature not a bug? I need to think more but for now I prefer 1 static set of JS and 1 static set of CSS - selected by me. Only way is manual and know-how of how plugin works.

    /* SHOW HANDLES FOR JS AND CSS */
    /* http://wpengineer.com/2308/debug-enqueued-scripts-and-styles-in-wordpress/ */
    /* http://wordpress.stackexchange.com/questions/54064/how-do-i-get-the-handle-for-all-enqueued-scripts?atw=1 */
    function wpa54064_inspect_scripts() {
       if ( current_user_can( 'administrator' ) ) {
          global $wp_scripts, $wp_styles;
             echo 'Names for enqueued scripts<br />';
          foreach( $wp_scripts->queue as $handle ) :
             echo $handle . '<br />';
          endforeach;
             echo '<br />Names for enqueued styles<br />';
          foreach( $wp_styles->queue as $handle ) :
             echo $handle . '<br />';
          endforeach;
       }
    }
    add_action( 'wp_footer', 'wpa54064_inspect_scripts' );

    If too much code for this forum here is Snippi link http://snippi.com/s/hjfevp0

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags