WordPress.org

Support

Support » Plugins and Hacks » [Resolved] add pagespeed_no_defer attribute

[Resolved] add pagespeed_no_defer attribute

Viewing 10 replies - 1 through 10 (of 10 total)
  • Mike

    @michael-copestake

    WPMU DEV Support Staff

    Hi @giorgosni

    This should do the trick:
    https://gist.github.com/toscho/1584783

    Either add the function to your functions.php or copy/paste the whole thing and create a new plugin.

    If you comment out this line then you can enable this for all javascript:
    FALSE === strpos( $url, 'contact-form-7' ) or

    Alternatively, I’m not a coder but this seems logical, you could replace ‘contact-form-7’ with ‘buddypress-activity-plus’ and see if that works.

    No promises of course 🙂

    Thanks Mike for your response,but unfortunately it wont work. I add the function below to the themes functions.php file but still don’t work. (note I want “no_defer” and not “defer “as the solution above is about)

    function add_pagespeed_no_defer_to_activity_plus( $url )
    {
        if ( FALSE === strpos( $url, 'buddypress-activity-plus' )
          or FALSE === strpos( $url, '.js' )
        )
        { // not our file
            return $url;
        }
        // Must be a ', not "!
        return "$url' defer='no_defer";
    }
    add_filter( 'clean_url', 'add_pagespeed_no_defer_to_activity_plus', 11, 1 );

    Hi there,

    From what I can tell, that’s checking against the name of the javascript file rather than the plugin. These are the file names enqueued by BuddyPress Activity Plus:

    bpfb_group_documents

    bpfb_interface

    Try replacing “contact-form-7” with either of those.

    Thanks arohmann for pointing this. It didn’t work either. script still not excluded from defer. the step where the return code is might be incorrect.

    this is the source of a script that gets the no-defer tag

    <script type="text/javascript" pagespeed_no_defer="">pagespeed.lazyLoadImages.overrideAttributeFunctions();</script>

    and this is what I get from activity plus:

    <script pagespeed_orig_type='text/javascript' src='http://p-1-ps.googleusercontent.com/h/wp-content/plugins/buddypress-activity-plus/js/bpfb_interface.js,qver=3.6.pagespeed.jm.qD8nvQV14O.js' defer='no_defer' type="text/psajs" orig_index="12"></script>

    I will keep looking…

    J K

    @jack-kitterhing

    WPMU DEV Support Staff

    Hi there,

    Thanks for your patience on this, I also can’t get this to work, going to discuss this with a few colleagues for you.

    Kind Regards
    Jack.

    J K

    @jack-kitterhing

    WPMU DEV Support Staff

    Hi there,

    Sorry about the delay on this, I’ve spoken with the lead developer and the following should work.

    <?php
    
    function add_pagespeed_no_defer_to_activity_plus( $url ) {
    if (!preg_match('/bpfb_[^\/]+\.js/', $url)) return $url;
    return "$url' defer='no_defer";
    }
    add_filter( 'clean_url', 'add_pagespeed_no_defer_to_activity_plus', 11, 1 );

    Thank you and sorry again about the delay.

    Kind Regards
    Jack.

    Thanks Jack for taking the effort to check.!! I will give it a try.

    Mike

    @michael-copestake

    WPMU DEV Support Staff

    Thanks for the reply, let us know how you get on please 🙂

    I have tested this and the behaviour is still the same. (activity input field area wont load) As pagespeed service from google is still in beta I will avoid to use the defer javascript rule as it is quite a high risk rewriter:

    This filter is considered high risk. JavaScript whose logic depends on the state of the DOM may behave differently when Defer JavaScript is turned on.

    https://developers.google.com/speed/pagespeed/service/DeferJavaScript

    Also other plugins besides Activity plus wont work correctly when defer javascript rule is enabled. e.g BP-gallery plugin can not remove images when the rule is enabled.

    So guys for the moment I appreciate your efforts, but I don’t wont to put you in more trouble on troubleshooting this.

    Lets wait till pagespeed service is out of beta. And also it might be another plugin that interferes..

    Mike

    @michael-copestake

    WPMU DEV Support Staff

    Ok that’s fair enough, if once it’s out of beta you still need help with this, then let us know and we’ll try and help again!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] add pagespeed_no_defer attribute’ is closed to new replies.