Recently I am using this plugin for integrating maps. But I have seen there are so many scripts and styles loaded in frontend and I don’t think that default methods are able to block them. I have tried below code :
Thank you for getting in touch, we do appreciate your time.
Although you can use standard hooks for dequeue calls, we usually advise instead using our dedicated developer hooks to manage these kinds of calls, as this ensures your load order will be respected as part of our initialization loops.
For example, your dequeue script would be written like this instead:
function wpgmza_dequeue_non_essential_dependencies($deps){
$dequeue = array('datatables', 'datatables-responsive', 'javascript-cookie');
foreach($dequeue as $dep){
if(!empty($deps[$dep])){
unset($deps[$dep]);
}
}
return $deps;
}
add_filter('wpgmza-get-library-dependencies', 'wpgmza_dequeue_non_essential_dependencies');
function wpgmza_dequeue_non_essential_styles(){
wp_dequeue_style('datatables');
wp_dequeue_style('wpgmaps_datatables_responsive-style');
wp_dequeue_style('fontawesome');
}
add_action('wpgmza_script_loader_enqueue_styles', 'wpgmza_dequeue_non_essential_styles', 9999);
Hi @dylanauty thank you so much for your response. Appreciate the hooks provided by you.
Q1. In that case it’s not able to restrict some js css in frontend as below.
CSS
wpgmaps_datatables_responsive-style
featherlight
owl-carousel_style
owl-carousel_style__default_theme
owl_carousel_style_theme_select
JS
featherlight
Q2.Also I noticed in my head tag there are some external scripts attached from googleapis can I control that also from hooks?
Q3. Also if possible can we get the lazy load feature for that because most of cases we use maps globally or on home page so its very laggy sometimes. If also able to make this for pro version that would fine. But we need lazy loading maps for better page speed.
Only a pleasure, happy to help where I can. Please find further responses below, in order:
This may be true, for some modules for various reasons. Owl Carousel assets can simply be disabled in the settings area. Maps > Settings > Marker Listings > Dependencies. The additional modules you mentioned are not core dependencies, and as such can instead be dequeued when the map is prepared for initialization, with this additional hook:
function wpgmza_dequeue_additional_dependencies(){
wp_dequeue_style('featherlight');
wp_dequeue_script('featherlight');
wp_dequeue_style('wpgmaps_datatables_responsive-style');
}
add_action('wpgooglemaps_hook_user_js_after_core', 'wpgmza_dequeue_additional_dependencies', 9999);
2. These additional scripts are all controlled directly by the Google Maps API, that is to say we simply include the API, with your appropriate API key and once verified, Google loads those additional scripts to support their API core.
3. Delayed, deferred, async and lazyloading is all supported in full. We do not offer this as a setting but integrate with plugins like LS Cache, WP Rocket, Async JavaScript which means you can enable most script optimization plugins, which support delayed loading, and see the addition of those tags in our inclusions.
Thanks @dylanauty appreciate your time spent for the thread. Worked settings as per you provided. Also appreciate the plugin is just awesome helped so many complex structures and saved so many hours of coding. Thanks again.