From 3bd97881fc300a4db8a6be4e2756d2745246134e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nora=20S=C3=B6derlund?= Date: Mon, 12 Feb 2024 11:11:18 +0100 Subject: [PATCH 1/2] chore: add loading=async to the urls with callbacks --- src/index.test.ts | 14 +++++++------- src/index.ts | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index 1e4618dd..99467995 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -25,10 +25,10 @@ afterEach(() => { }); test.each([ - [{}, "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback"], + [{}, "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&loading=async"], [ { apiKey: "foo" }, - "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&key=foo", + "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&loading=async&key=foo", ], [ { @@ -38,23 +38,23 @@ test.each([ language: "language", region: "region", }, - "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&key=foo&libraries=marker,places&language=language®ion=region&v=weekly", + "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&loading=async&key=foo&libraries=marker,places&language=language®ion=region&v=weekly", ], [ { mapIds: ["foo", "bar"] }, - "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&map_ids=foo,bar", + "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&loading=async&map_ids=foo,bar", ], [ { url: "https://example.com/js" }, - "https://example.com/js?callback=__googleMapsCallback", + "https://example.com/js?callback=__googleMapsCallback&loading=async", ], [ { client: "bar", channel: "foo" }, - "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&channel=foo&client=bar", + "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&loading=async&channel=foo&client=bar", ], [ { authReferrerPolicy: "origin" }, - "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&auth_referrer_policy=origin", + "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&loading=async&auth_referrer_policy=origin", ], ])("createUrl is correct", (options: LoaderOptions, expected: string) => { const loader = new Loader(options); diff --git a/src/index.ts b/src/index.ts index 434609cb..546f5c15 100644 --- a/src/index.ts +++ b/src/index.ts @@ -369,7 +369,7 @@ export class Loader { public createUrl(): string { let url = this.url; - url += `?callback=__googleMapsCallback`; + url += `?callback=__googleMapsCallback&loading=async`; if (this.apiKey) { url += `&key=${this.apiKey}`; From 3cede183cf44935c0276281ec553d47d4f0faf0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nora=20S=C3=B6derlund?= Date: Mon, 12 Feb 2024 14:41:28 +0100 Subject: [PATCH 2/2] chore: fix linting --- src/index.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.test.ts b/src/index.test.ts index 99467995..aa01f239 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -25,7 +25,10 @@ afterEach(() => { }); test.each([ - [{}, "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&loading=async"], + [ + {}, + "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&loading=async", + ], [ { apiKey: "foo" }, "https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&loading=async&key=foo",