Google Place Autocomplete js libs cause bad lighthouse rating on mobile

Viewed 8

We have a search field on our most visited pages which has google places autocomplete enabled. Users can input their location and get relevant results.

When checking these pages using lighthouse (mobile), we see that 5 scripts are loaded by google, totaling 231kb, which is quite a lot on mobile. Also, Lighthouse shows these scripts in the category "Reduce unused JavaScript"

This is the call that loads all these scripts:

https://maps.googleapis.com/maps/api/js?libraries=places&language=de&key=APIKEY&callback=initAutocomplete

  1. Is there a solid, user friendly way to either load these scripts only when users actually use the location search field? I imagine that if we were to do this, it could cause UX issues with users on a bad connection - They start inputting their text into the search field, we start loading the libs. Libs take a long time to load and users never even see the suggestions..

  2. Or is there a way to load less scripts (for me it seems kind of strange that 5 libs are loaded just for the autocomplete functionality...)?

Cheers

0 Answers
Related