Currently the module loads the Google Maps JS on every page, even if on the page there is any map.
Steps to reproduce
- create a new block type
- add a geofield field on the new block type
- set the styled google map visualization style
- create a block of the newly created type
- add the block only on the front page
- open a different page and check the source code.
To fix
Move the two external JS libraries into style_google_map.libraries.yml:
styled-google-map:
version: 1.0
js:
//maps.google.com/maps/api/js: { type: external }
//cdn.rawgit.com/googlemaps/js-info-bubble/gh-pages/src/infobubble.js: { type: external }
js/styled-google-map.js: {}
css:
css/styled-google-map.css : {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
Then remove the styled_google_map_page_attachments() function from the .module file.
The map still works and now the JS is loaded only if necessary.
Comments
Comment #2
a.dmitriiev commentedI will take a look at this during this week.
Comment #3
finex commentedThanks, let me know :-)
Comment #4
geerlingguy commentedJust noticed this on my site as well; attached patch implements the suggestion in the original issue summary, and is tested and working on my site (the maps JS only loads on pages where a map/field is present and the library files are loaded).
Comment #5
geerlingguy commentedCleaned up issue summary.
Comment #7
a.dmitriiev commentedThank you guys,
I added this to dev version. I will gather some more patches and changes and will create a stable release a bit later
Comment #8
a.dmitriiev commented