Skip Navigation

[Resolved] Which JS to defer?

This thread is resolved. Here is a description of the problem and solution.

Problem:

How to force the Javascript file of the Maps plugin to load at a later time?

Solution:

There is no such an option in Toolset.

You can force Toolset to avoid loading the Map Javascript files by adding the code below:

function my_dequeue_script() {
wp_deregister_script( 'google-maps' );
wp_dequeue_script( 'google-maps' );
}
add_action( 'wp_print_scripts', 'my_dequeue_script', 200 );

After that, you can add the Javascript files below at a later time that you want:

/wp-content/plugins/toolset-maps/resources/js/jquery.geocomplete.min.js
/wp-content/plugins/toolset-maps/resources/js/views_filter_distance_frontend.js
/wp-content/plugins/toolset-maps/resources/js/wpv_addon_maps.js

This support ticket is created 2 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by AzzurraM25 2 years, 6 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2503983
Schermata 2022-11-25 alle 16.31.22.png

Hi there,
I've just published a new Toolset website and for the first time I'm getting very low results for Speed performances (around 40 for mobile). I'm using SG Optimizer for caching ect but I'm trying to see if there's anything else that I can do.
I've tried activating the Defer Render-blocking JavaScript option in SG Optimizer but then both the map and the view of brand logos at the bottom is messed up. I can exclude some JS from being deferred, so I tried the ones selected at the top of the attached screenshot. It sorted it out for the View but the map still disappears. Would you be so kind as to indicate which JS corresponds to the map so I can exclude it?

Thank you very much

#2504813

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

From the screenshot that you gave, under the Others category, none of the options are part of Toolset.

But maybe you need to avoid deferring the core jQuery file.

From what I know these are the files that Toolset Map loads:

/wp-content/plugins/toolset-maps/resources/js/jquery.geocomplete.min.js
/wp-content/plugins/toolset-maps/resources/js/views_filter_distance_frontend.js
/wp-content/plugins/toolset-maps/resources/js/wpv_addon_maps.js

Even the files above are not loaded every time, it depends on which option of the Maps plugin is used on that particular page.

That is what I can help with in terms of the JS files loaded by the Maps plugin.

Thanks.

#2505249

Thank you, Christopher...I see.
So, the problem might be with Google Maps JS itself. How can I add "async" and "defer" to the Maps JS in Toolset then?
Thank you

#2505469

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

I am afraid that is not possible, the reason is that you will need to change the core code of Toolset and whatever you do it will be deleted the next time you update the Toolset Maps plugin.

One thing that I can suggest is that you force Toolset not to load the Google Maps Javascript code altogether by adding the code below to functions.php file of your theme:

function my_dequeue_script() {
wp_deregister_script( 'google-maps' );
wp_dequeue_script( 'google-maps' );
}
add_action( 'wp_print_scripts', 'my_dequeue_script', 200 );

Then you can decide how to add the Javascript code yourself and whenever you want.

But this goes into the custom coding realm which is outside of our support scope.

You are welcome to hire a developer for such a customization:

https://toolset.com/contractors/

Thanks.

#2506123

I see. Thank you for your answer