Performance concerns
-
It’s nice to see that the Javascript error finally fot fixed and the nag can now be dismissed ??
This plugin loads files that are not required on pages where it is not enabled. For instance, i have the share button turned off for the home page, but it still makes 4 http requests to facebook and 3 http requests to sharethis. This adds about 50% to the load time on a phone.
Also (a much smaller concern), it would increase the PageSpeed score by about 3 if the button icons were delivered as a sprite, so only one http request for them all instead of one per button.
Otherwise, still the best share button plugin out there, as far as i’m concerned.
-
I just wanted to chime in on this as well, when Share Buttons are activated they load on every page even the pages where I have it turned off. With SSBA deactivated my gtmetrix.com page load score is an A, with it activated, the score is a C. I too love this share plugin but I can’t use it because it slows down my page load too much. Thanks!
Can someone provide a solution for a code snippet that would deregister the script and styles on pages that don’t need it? For pasting into functions.php I mean?
Here is a sample but I don’t think I’ve got this right, and not sure how to do it for the multiple scripts in this plugin, which are problematic, as noted above
/** * Remove scripts + styles unless we're on the page * */ add_action( 'wp_enqueue_scripts', 'ac_remove_scripts' ); function ac_remove_scripts() { if ( is_home() ) { wp_deregister_style( 'not-sure-what-goes-here' ); wp_deregister_script( 'not-sure-what-goes-here' ); } }
Here are references for what I’m trying to do:
https://inspirationalpixels.com/tutorials/remove-plugin-scripts-wordpress
https://www.fldtrace.com/load-javascript-on-specific-pages-in-wordpress
https://css-tricks.com/taking-control-cssjs-wordpress-plugins-load/Any help here would be greatly appreciated.
Just read this on another plugin if it helps: https://www.wpbeginner.com/floating-social-bar/ – but haven’t tried it out yet.
It might make more sense, rather than deregistering scripts, to just not register them in the first place, except where you are going to deploy this plugin on the page. You should already know from the settings whether the page you are on requires the scripts. Just check the settings before registering scripts and don’t do it if you don’t need them for the current page.
Sure that could work, but not sure how to do it – any help?
Or are you suggesting to use the shortcode option?
As you’ve noted above, telling the plugin settings where you want to turn ‘off’ the share buttons doesn’t remove the scripts from the site’s pages.
But there are some basic instances where we’d want all posts and pages to have them, which will be the ‘most likely’ case. So that’s why I thought only if we don’t want them on a page, like the home page for instance, it would be better to deregister them in those cases?
Or am I not understanding?
I will take a look at your code and see if i can make some specific suggestions.
FYI … when i go to the settings page i see a PHP error :
Notice: Undefined index: ssba_custom_facebook_save in F:\theme-dev\nelson-base.dev\www\wp-content\plugins\simple-share-buttons-adder\inc\ssba_admin_panel.php on line 362
This is version 6.3.4
You may need to show all PHP errors in your development environment to see this.
Um… On sites where this plugin was installed earlier and was upgraded to 6.3.4, it is working, but a fresh install of 6.3.4 where the plugin was never installed, seems to not be working. No errors. It just doesn’t work.
I’m unable to test anything without a working verison, but will look through your code anyway, as mentioned above.
Here’s the reason that v6.3.4 is not working for me. Filtering the content from within the wp_head hook does not work. Here is that code from ssba_buttons.php
function ssba_add_button_filter() {
$arrSettings = get_ssba_settings();
add_filter( ‘the_content’, ‘show_share_buttons’, (int) $arrSettings[‘ssba_content_priority’] );
}
add_action( ‘wp_head’, ‘ssba_add_button_filter’, 99 );I found that it works if i add the content filter without using the wp_head hook, as follows :
add_filter( ‘the_content’, ‘show_share_buttons’, (int) get_ssba_settings()[‘ssba_content_priority’] );
Hi again. I’ve never used this plugin on excerpts, and i see that it’s not working for me on excerpts. I will look into this. Meanwhile, in the next post is a fix to only add scripts and style when the buttons are actually used on a page.
— shanna
To modify this plugin so that it only adds scripts and style when buttons are actually used on a page, make the following changes to inc/ssba_styles.php
1. Create a new function to check whether buttons are actually used.
// check if this page requires buttons
function ssba_are_buttons_required($arrSettings) {if (isset($arrSettings[‘ssba_pages’]) && $arrSettings[‘ssba_pages’] == ‘Y’ && is_page()) return TRUE;
else if (isset($arrSettings[‘ssba_posts’]) && $arrSettings[‘ssba_posts’] == ‘Y’ && is_single()) return TRUE;
else if (isset($arrSettings[‘ssba_cats_archs’]) && $arrSettings[‘ssba_cats_archs’] == ‘Y’ && is_category()) return TRUE;
else if (isset($arrSettings[‘ssba_cats_archs’]) && $arrSettings[‘ssba_cats_archs’] == ‘Y’ && is_archive()) return TRUE;
else if (isset($arrSettings[‘ssba_homepage’]) && $arrSettings[‘ssba_homepage’] == ‘Y’ && is_home()) return TRUE;
else if (isset($arrSettings[‘ssba_homepage’]) && $arrSettings[‘ssba_homepage’] == ‘Y’ && is_front_page()) return TRUE;
else if (isset($booShortCode) && $booShortCode == TRUE) return TRUE;
else return FALSE;}
2. Call the new function near the top of ssba_page_scripts :
function ssba_page_scripts() {
// get settings
$arrSettings = get_ssba_settings();// are buttons needed for this page?
if (!ssba_are_buttons_required($arrSettings)) return;…
}
3. Call the new function near the top of get_ssba_style :
function get_ssba_style() {
// query the db for current ssba settings
$arrSettings = get_ssba_settings();// are buttons needed for this page?
if (!ssba_are_buttons_required($arrSettings)) return;…
}
Hope this works for you. My (somewhat superficial) testing shows that it eliminates the unneeded HTTP requests.
— shanna
ok, i think we’re all good on the excerpts too… The plugin does it’s thing to the excerpt before the theme gets the excerpt, so any theme that plays with the excerpt can mess up or remove the buttons. In this case my theme was doing that, and i’ve fixed it.
Looking forward to a new version of ssba with these fixes (hopefully they will work for you in a thorough testing) …
Thanks for looking at this.
— shanna
P.S. – I am finding it impossible to tell the difference between using categories/archives and using excerpts, as they seem to do the same thing – both adding buttons to the excerpts. This is also the case with the front page (but not home page, obviously). What i would have expected is that excerpts and categories/archives would operate independently, with excerpts adding buttons to individual excerpts and categories/archives adding one set up buttons for the whole page. Right now excerpts doesn’t even seem to work unless categories/archives is also enabled. So i think there is definitely some confusion here in what functionality to expect for the applicable page-type settings. I found that it’s easy enough to make excerpts work independently by adding ssba_excerpts to the check in show_share_buttons, and to the check i added called ssba_are_buttons_required. With that the excerpts will show without enabling categories/archives, but categories/archives still won’t display one set of buttons for the whole page, nor does the home page when it’s a front page. Maybe i’ll play with this a bit more later.
Note that WordPress converts single quotes to curly quotes. You’ll have to fix those in the code posted here.
I made a small change to this function :
// check if this page requires buttons
function ssba_are_buttons_required($arrSettings) {if (isset($arrSettings[‘ssba_pages’]) && $arrSettings[‘ssba_pages’] == ‘Y’ && is_page()) return TRUE;
else if (isset($arrSettings[‘ssba_posts’]) && $arrSettings[‘ssba_posts’] == ‘Y’ && is_single()) return TRUE;
else if (isset($arrSettings[‘ssba_cats_archs’]) && $arrSettings[‘ssba_cats_archs’] == ‘Y’ && is_category()) return TRUE;
else if (isset($arrSettings[‘ssba_cats_archs’]) && $arrSettings[‘ssba_cats_archs’] == ‘Y’ && is_archive()) return TRUE;
else if (isset($arrSettings[‘ssba_homepage’]) && $arrSettings[‘ssba_homepage’] == ‘Y’ && is_home()) return TRUE;
else if (isset($arrSettings[‘ssba_homepage’]) && $arrSettings[‘ssba_homepage’] == ‘Y’ && is_front_page()) return TRUE;
else if (isset($arrSettings[‘ssba_excerpts’]) && $arrSettings[‘ssba_excerpts’] == ‘Y’ && (is_category() || is_archive() || is_home())) return TRUE;
else if (isset($booShortCode) && $booShortCode == TRUE) return TRUE;
else return FALSE;}
Please see my separate post on the confusing distinction of excerpts vs categories/archives. I have fixed this for my own use and posted the code changes.
https://www.ads-software.com/support/topic/confusing-functionality-excerpts-and-categoriesarchives/
Ok, so this turned into a messy pile of code above and i’ve decided to post a link to my own modified version of this plugin, which addresses these concerns until the developer gets around to it. This is a drop-in replacement and you’ll easily be able to go back to the real thing at any time.
https://wildmice.ca/downloads/simple-share-buttons-adder-fixed-6.3.4.zip
- The topic ‘Performance concerns’ is closed to new replies.