javascriptjquerygeolocationcountry-codes

JS Geolocation countries dropdown


I use get ipapi.co/country for detecting the location country and then to make the select option active depending on this location. But it makes the form a little bit slow to render the country option. Can anyone recommend if I can make the response faster? This is the code I'm using:

$.get("https://ipapi.co/country/", function (t) {
            (clientCountry = "AU"), (clientCountry = t), $("#country option[value=" + clientCountry + "]").val(), $("#country option[value=" + clientCountry + "]").attr("selected", "selected");
            var e = $("#country option:selected").attr("age");
            $("#age-gate__country .ui-selectmenu-status").text($("select[name=country] option:selected").text());
            var a = new Date(new Date().setFullYear(new Date().getFullYear() - e)).toLocaleDateString("en-US");
        }),

Solution

  • The code is so simple that I doubt is the performance bottleneck. The API or the request may be the bottleneck but that cannot be fixed (at least not by you but only by the API provider).