-
AuthorPosts
-
November 1, 2017 at 7:39 pm #871360
Hi guys
Thanks for the latest updates (4.2).In an attempt to get on the right side of PageSpeed (especially now we have Google Lighthouse to report on mobile UX) I can get JQuery (/wp-includes/js/jquery/jquery.js) to be deferred to the footer (via WP-Rocket) which is a major breakthrough. Good news!
However, doing so breaks the Masonry and Special Heading Elements. Is there anything that can be done about that? I appreciate it’s not in your list of mods but I do consider Page Speed a critical part of SEO efforts and a theme that can successfully parse non-critical JS and CSS to after the fold is going to be light years ahead of most others.
Something to consider perhaps?
Thanks
EdNovember 1, 2017 at 8:16 pm #871365This is normal registering of wordpress and not specific to enfold.
I don’t know how WP-Rocket tries to do so.
if i would like to do so i will first deregister it and than register it back again f.e.i have sometimes this on my functions.php –
that loads the jquery via cdn from google servers – if it exists (or a internet connection is present)
if not it will load the normal jquery from folder – but i do not have success on loading it in the footer.if( !is_admin()){ $url = 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'; $test_url = @fopen($url,'r'); if($test_url !== false) { function load_external_jQuery() { wp_deregister_script('jquery'); wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js'); wp_enqueue_script('jquery'); } add_action('wp_enqueue_scripts', 'load_external_jQuery'); } else { function load_local_jQuery() { wp_deregister_script('jquery'); wp_register_script('jquery', '/wp-includes/js/jquery/jquery.js', __FILE__, false, '1.12.4', true); wp_enqueue_script('jquery'); } add_action('wp_enqueue_scripts', 'load_local_jQuery'); } }
i tested it with google loading – and it is no performance profit on it.
but on enfold the avia-compat.js is loaded in the header – maybe this is the reason for inconsitencies if jquery is in the footer (after avia-compat.js)
November 1, 2017 at 8:29 pm #871370by the way – all those loaders are in script-loader.php in wp-includes (of wordpress itself)
before WP 3.9 i did it sometimes with :
if( !is_admin()){ function load_local_jQuery() { wp_deregister_script('jquery'); wp_register_script('jquery', '/wp-includes/js/jquery/jquery.js', __FILE__, false, '1.12.4', true); wp_enqueue_script('jquery'); } add_action('wp_enqueue_scripts', 'load_local_jQuery'); }
but it does not work on new wp
November 1, 2017 at 8:29 pm #871371Thank you @Guenni007
Very kind of you to take the time to answer.
I suspect the avia-compat.js is the problem here but I am unsure. WP-Rocket has got all clever and can defer everything that isn’t required to render the page – but that has issues. I may try to load from an external script as you suggest to see what happens.
I’m not hung up on PageSpeed scores but do take User Experience very seriously. Everything tells me to defer JS wherever I can – and it would be nice to achieve this and still get the site load properly. It’s a bit beyond my technical skills though.
Thanks again
EdNovember 2, 2017 at 9:13 am #871567i suppose that there are too many dependencies to other js files needed jquery. So every one of these has to be under the jquery loading.
November 2, 2017 at 1:44 pm #871654Hi,
jQuery is needed to load a lot of the elements generated by the theme, there is a reason as to why it’s loaded in the header :-)
You might find useful information in this thread: https://kriesi.at/support/topic/seo-google-page-insights-blocking-rendering-ressources-above-the-fold/
Best regards,
RikardNovember 2, 2017 at 11:35 pm #871879Thanks @Rikard
I understand and appreciate the link to the extensive post on the subject; I’m so close to making it work it’s crazy! I think I need to learn some JS. Interestingly WP-Rocket has a brilliant Critical CSS and JS generator with just two small issues I cannot solve – it defers JQeury perfectly well – if only I could solve these two little problems I would be laughing!
Thanks to all who have contributed thus far; kudos!
Regards
EdNovember 3, 2017 at 12:04 pm #872113 -
AuthorPosts
- You must be logged in to reply to this topic.