Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR - Remove jQuery dependency #113

Closed
JiveDig opened this issue Mar 3, 2021 · 4 comments
Closed

FR - Remove jQuery dependency #113

JiveDig opened this issue Mar 3, 2021 · 4 comments

Comments

@JiveDig
Copy link

JiveDig commented Mar 3, 2021

I just wanted to make an official feature request to remove the dependency on jQuery. For many of our client sites and theme demos we'd like to use Shared Counts (has been our go to for a while) but on many of these sites it's the only plugin relying on jQuery, which causes performance issues. I know it's not a big deal to many, but we see much better pagespeed and lighthouse scores on sites/pages without jQuery.

Figured I'd throw this out there to see what y'all think :)

@billerickson
Copy link
Collaborator

I agree, that would be a good move.

Personally I disable all the JavaScript and CSS from Shared Counts and change the email link to a mailto link, both to remove the need for the JS and markup for the modal, but also to decrease spam / remove the need for reCAPTCHA.

I'm not very good with vanilla JS. Would you be able to update Shared Counts to remove the dependency without reducing functionality (ie: modal still works)? Or should we include a "no JavaScript" option in the plugin that replicates what I already do on my client sites?

@JiveDig
Copy link
Author

JiveDig commented Mar 3, 2021

Or should we include a "no JavaScript" option in the plugin that replicates what I already do on my client sites?

Oh that's a good idea. That seems like the path of least resistance. Then another update at some point could remove jQuery. I could probably do it, but it would be a while.

I'd love a snippet if you have that handy too btw :)

@billerickson
Copy link
Collaborator

Here's what I do:

<?php
/**
 * Shared Counts
 *
 * @package      Cultivate
 * @author       CultivateWP
 * @since        1.0.0
 * @license      GPL-2.0+
 **/

// Disable CSS and JS.
add_filter( 'shared_counts_load_css', '__return_false' );
add_filter( 'shared_counts_load_js', '__return_false' );

/**
 * Simple email button
 * Does not require loading JS
 *
 * @param array $link Link.
 * @param int   $id ID.
 */
function be_shared_counts_email_link( $link, $id ) {
	if ( 'email' !== $link['type'] ) {
		return $link;
	}

	$subject      = esc_html__( 'Your friend has shared an article with you.', 'shared-counts' );
	$subject      = apply_filters( 'shared_counts_amp_email_subject', $subject, $id );
	$body         = html_entity_decode( get_the_title( $id ), ENT_QUOTES ) . "\r\n";
	$body        .= get_permalink( $id ) . "\r\n";
	$body         = apply_filters( 'shared_counts_amp_email_body', $body, $id );
	$link['link'] = 'mailto:?subject=' . rawurlencode( $subject ) . '&body=' . rawurlencode( $body );

	return $link;
}
add_filter( 'shared_counts_link', 'be_shared_counts_email_link', 10, 2 );
add_filter( 'shared_counts_disable_email_modal', '__return_true' );

@billerickson
Copy link
Collaborator

Now that I look at it, I remember that I already built this functionality into Shared Counts for when AMP is active :)

https://github.com/jaredatch/Shared-Counts/blob/develop/includes/class-shared-counts-amp.php

But I agree, there should be an option to enable this for non-AMP pages too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants