BuddyPress Activity Plus
[resolved] add pagespeed_no_defer attribute (11 posts)

  1. giorgosnl
    Posted 2 years ago #

    I use pss (google pagespeed service) and I use the defer JS rewrite rules. All plugins works fine except the activity plus. I would like to place the "pagespeed_no_defer" attribute tag to exclude it from this rule as advised by google here: https://developers.google.com/speed/pagespeed/service/DeferJavaScript

    Any idea how to achieve that?

    A function is used as described below but is not for this plugin.


  2. Mike
    WPMU DEV Support Staff
    Posted 2 years ago #

    Hi @giorgosni

    This should do the trick:

    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 :-)

  3. giorgosnl
    Posted 2 years ago #

    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 );
  4. arohmann
    Posted 2 years ago #

    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:



    Try replacing "contact-form-7" with either of those.

  5. giorgosnl
    Posted 2 years ago #

    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...

  6. 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

  7. Hi there,

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

    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

  8. giorgosnl
    Posted 2 years ago #

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

  9. Mike
    WPMU DEV Support Staff
    Posted 2 years ago #

    Thanks for the reply, let us know how you get on please :-)

  10. giorgosnl
    Posted 2 years ago #

    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.


    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..

  11. Mike
    WPMU DEV Support Staff
    Posted 2 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • BuddyPress Activity Plus
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic