Divi Speedup: Stop Map Module Excerpts Loading Google Maps Scripts
I recently noticed that the Divi Theme sometimes loads Google Maps, even when there are no maps in the page. This results in around 5 unnecessary requests on those pages. Preventing these requests will speed up the loading of these pages.
It turns out that the pages in question all showed an excerpt of a post containing a map module (or fullwidth map module). While the map module isn't displayed as part of the generated excerpt, the act of generating the excerpt fully processes the post and triggers the map module to load the scripts it requires – i.e. the Google Maps scripts.
Since the excerpts don't display a map, they don't need to load the scripts. Here's how to prevent this behavior and save around 5 requests on post listing pages.
Using Divi Booster to Stop Unnecessary Loading of Google Maps Scripts
I've added an option into Divi Booster to prevent excerpts from loading the Google Maps scripts unnecessarily.
It can be found on the Divi Booster settings page at "Site-wide Settings > Site Speed > Stop map module excerpts from unnecessarily loading maps scripts". Simply enable the option and save.
Once applied, pages which show excerpts of posts containing map modules should run that bit quicker.
The option is available in Divi Booster 2.7.7 onwards.
Using PHP to Stop Unnecessary Loading of Google Maps Scripts
If you'd prefer to go down the DIY route, you can use the following PHP code to achieve the same effect:
Related Post: Adding PHP to the Divi Theme
Want get more out of Divi?
Hundreds of new features for Divi
in one easy-to-use plugin