Skip to content

Commit

Permalink
fix: add loading=async to the urls with callbacks (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
nora-soderlund committed Feb 15, 2024
1 parent 2e2b8c4 commit 2d05217
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ 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",
],
[
{
Expand All @@ -38,23 +41,23 @@ test.each([
language: "language",
region: "region",
},
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&key=foo&libraries=marker,places&language=language&region=region&v=weekly",
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&loading=async&key=foo&libraries=marker,places&language=language&region=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);
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down

0 comments on commit 2d05217

Please sign in to comment.