• Resolved nicole0155

    (@nicole0155)


    The script /wp-content/plugins/wordpress-popular-posts/assets/js/wpp.min.js its being loaded in all wordpress pages.

    Since the plugin WPP its only used at blog pages (with the shorcode), how can I avoid this script loading?

    I have Perfmatters installed to avoid loading some plugins in specific pages. However on Perfatters I only see /wp-content/plugins/wordpress-popular-posts/assets/css/wpp.css to be disabled and not the script.

    Thank you.

    • This topic was modified 5 months ago by nicole0155.
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @nicole0155,

    That script not only handles the dynamic loading of your popular posts list (when the Ajaxify function is enabled, which it is by default) but also tracks every post / page view. That’s why it’s loaded everywhere and not only where your shortcode is.

    Additionally, that script is -off the top of my head- around 3 KBs in size. Not loading this file won’t make a difference in your performance metrics -not a noticeable one at least- since the file is super small and should load super fast for 99.9% of your visitors anyways. And I’m telling you this as someone who develops websites for a living every day ??

    Thread Starter nicole0155

    (@nicole0155)

    Hi @hcabrera

    Thanks for your fast reply.

    In spite of the file being super small, we do not see the need of load such script everywhere.

    Every day, we have more than 100 000 lines at the access logs, just due to accesses from a few internal and external tools. Much more lines with the normal visitors.

    Is there a way of avoiding this script load every page (without disabling the plugin)?

    Thanks.

    Plugin Author Hector Cabrera

    (@hcabrera)

    Is there a way of avoiding this script load every page (without disabling the plugin)?

    You could try using the wp_script_attributes filter hook to have WordPress output an empty script tag when $attr['src'] contains wpp.js or wpp.min.js, which is kind of “hacky” but it may work.

    Thread Starter nicole0155

    (@nicole0155)

    I have checked now that even some bots started to load the script. Not sure if this started with the 7.00 version.

    I have tested the following code, but its not working. Any suggestion?

    function filter_wpp_script_attributes($attr, $handle) {
    if ($handle === 'wpp' || $handle === 'wpp.min') {
    if (is_product()) {
    return array(
    'src' => '',
    );
    }
    }
    return $attr;
    }
    add_filter('script_loader_tag', 'filter_wpp_script_attributes', 10, 2);



    Would be possible to use somethink like? In that case what should be the script identification?

    function dequeue_wpp_script_on_products() {
    if (is_product()) {
    wp_dequeue_script('wpp');
    wp_deregister_script('wpp');
    }
    }
    add_action('wp_print_scripts', 'dequeue_wpp_script_on_products', 100);
    Plugin Author Hector Cabrera

    (@hcabrera)

    None of those hooks will work, that’s why I suggested using the wp_script_attributes one instead.

    For example:

    add_filter('wp_script_attributes', function($atts) {
    if (
    is_product()
    && (str_contains($atts['src'], 'wpp.js') || str_contains($atts['src'], 'wpp.min.js'))
    ) {
    $atts['src'] = '';
    }

    return $atts;
    });

    I have checked now that even some bots started to load the script. Not sure if this started with the 7.00 version.

    Bots will try to crawl everything they can find on a page so I don’t think it’s something new.

    • This reply was modified 4 months, 4 weeks ago by Hector Cabrera. Reason: Added sample code snippet
    Thread Starter nicole0155

    (@nicole0155)

    We have tested several hooks, but couldn’t make it work. Can you provide a suggestion?

    Plugin Author Hector Cabrera

    (@hcabrera)

    The one I posted above worked on my end. Have you tried it yet?

    Thread Starter nicole0155

    (@nicole0155)

    Sorry, it seems I have miss your code.

    Its working! Many thanks

    Can this be done so that it only unloads the script on the front page of the site, and not post pages?

    Plugin Author Hector Cabrera

    (@hcabrera)

    Yup, untested but I think this should work @ispreview :

    add_filter('wp_script_attributes', function($atts) {
    if (
    is_home()
    && (str_contains($atts['src'], 'wpp.js') || str_contains($atts['src'], 'wpp.min.js'))
    ) {
    $atts['src'] = '';
    }

    return $atts;
    });

    or this:

    add_filter('wp_script_attributes', function($atts) {
    if (
    is_front_page()
    && (str_contains($atts['src'], 'wpp.js') || str_contains($atts['src'], 'wpp.min.js'))
    ) {
    $atts['src'] = '';
    }

    return $atts;
    });

    Depending on your site’s configuration one or the other will do the trick.

    Perfect, thanks Hector.

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.