• Wonder if there is an option to load script(s) async for better speed on load. Got this console warning load ing the site in Safari:

    Google Maps JavaScript API has been loaded directly without loading=async. This can result in suboptimal performance. For best-practice loading patterns please see https://goo.gle/js-api-loading

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter Rhand

    (@rhand)

    Besides async loading conditionally loading would be great too. Seems all Maps JS is loaded even when we do not use the map

    <link rel="dns-prefetch" >
    ...
    <link rel="stylesheet" id="bootstrap-css-css" type="text/css" media="all">
    <link rel="stylesheet" id="frontend_main-css-css" type="text/css" media="all">
    ..
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places%2Cgeometry&amp;v=3.exp&amp;language=de&amp;key=xxxxxxxxxx-A&amp;ver=6.6.2" id="gmwd_map-js-js"></script>
    <script type="text/javascript" src="https://domain.nl/wp-content/plugins/wd-google-maps/js/init_map.js?ver=1.0.64" id="frontend_init_map-js-js"></script>
    <script type="text/javascript" src="https://domain.nl/wp-content/plugins/wd-google-maps/js/frontend_main.js?ver=1.0.64" id="frontend_main-js-js"></script>

    But we may apply something like

    function dequeue_google_maps_assets() {
    // List of page/post IDs or slugs where you want to dequeue
    $excluded_pages = array(
    123, // Replace with actual page/post ID
    'your-page-slug', // Replace with page slug
    );

    // Check if the current page is in the excluded list
    if (is_page($excluded_pages) || is_single($excluded_pages)) {
    wp_dequeue_style('bootstrap-css-css');
    wp_dequeue_style('frontend_main-css-css');
    wp_dequeue_script('gmwd_map-js-js');
    wp_dequeue_script('frontend_init_map-js-js');
    wp_dequeue_script('frontend_main-js-js');
    }
    }
    add_action('wp_enqueue_scripts', 'dequeue_google_maps_assets', 20);
    • This reply was modified 2 months, 3 weeks ago by Rhand.
    • This reply was modified 2 months, 3 weeks ago by Rhand.
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.