- This topic has 7 replies, 3 voices, and was last updated 1 year, 9 months ago by
David.
-
AuthorPosts
-
September 17, 2020 at 6:10 pm #1447925
maxime
Hello,
First of all thank you it’s a great theme.
I would like to remove the jQuery 1.12.4 which is unused.
I found out that it was only called from the plugin WP Show Post. And only when it is an Element Hook with shortcode or PHP at the end of a post, not on widget.
In my cPanel I moved this file, it seems like it didn’t break the plugin and in PageSpeed Insight it removed the unused JavaScript as well so it was great but in GTmetrix it counts as a bad request which is less great.So my question is, is it possible to remove this JavaScript 1.12.4 of the plugin WP Show Post without consequences ?
I found this code :function my_jquery_enqueue() {
wp_deregister_script( ‘jquery’ );
}add_action( ‘wp_enqueue_scripts’, ‘my_jquery_enqueue’ );
Is it any good?
Or would it be better to deactivate the Element Hook ?Thank you,
MaxSeptember 17, 2020 at 6:28 pm #1447930Elvin
StaffCustomer SupportBefore doing this, you must really be sure that no theme or plugin has a dependency on it.
If you’re 100% sure there none, you can proceed with using this code.
add_action('wp_enqueue_scripts', 'no_more_jquery'); function no_more_jquery(){ wp_deregister_script('jquery'); }
It’s basically the same as the code you’ve provided except I’ve fixed the
β β
syntax.Or would it be better to deactivate the Element Hook ?
It won’t remove the enqueued jQuery as this is automatically loaded in WordPress by default regardless if its used or not. The WP native
wp_deregister_script()
function is the way to unload this.A wise man once said:
"Have you cleared your cache?"September 18, 2020 at 6:25 am #1448557maxime
Thank you for fixing the code.
Just one last question, when you say
no theme or plugin has a dependency on it.
It’s about JavaScript in general or just the jQuery 1.12.4 ?
Because about the jQuery 1.12.4 I looked for every plugin by deactivate them one by one and only WP Show Post was showing this request.
If it’s about any JavaScript, is there a way to know if a plugin needs JavaScript ? And in this case I won’t activate the function.
Thank you
September 18, 2020 at 7:18 am #1448632David
StaffCustomer SupportHi there,
GP by default does not request jQuery – unless you enable the Sticky Navigation, which is the only function that still relies on jQuery.
So if a plugin requires jQuery it should make the request for it.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 18, 2020 at 7:23 am #1448642maxime
Okay thank you I’ll check every plugin then in the source code.
September 18, 2020 at 7:49 am #1448824David
StaffCustomer SupportCheck the Network tab on a private / incongito browser ( as there is no cache ) – to see if jQuery is requested π Simply keep refreshing after each plugin activation.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/September 18, 2020 at 8:22 am #1448880maxime
Perfect, I’ll do that. Thank you π
September 18, 2020 at 2:56 pm #1449301David
StaffCustomer SupportYou’re welcome
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.