From 744bd9d1be2aa7f3dc203ea393224cce811bc63d Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 16 Aug 2021 13:37:36 +0100 Subject: [PATCH] Only load Google Maps JS where it's actually needed --- app/views/groups/show.html.haml | 3 +++ app/views/layouts/darkswarm.html.haml | 5 +---- app/views/map/index.html.haml | 3 +++ app/views/producers/index.html.haml | 3 +++ app/views/registration/index.html.haml | 3 +++ app/views/shared/_google_maps_js.html.haml | 2 ++ app/views/shops/index.html.haml | 3 +++ 7 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 app/views/shared/_google_maps_js.html.haml diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index df1152bd70..233806ce92 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -5,6 +5,9 @@ - content_for(:image) do = @group.logo.url +- content_for :scripts do + = render partial: "shared/google_maps_js" + - content_for :injection_data do = inject_available_countries = inject_group_enterprises diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index 82c36ee492..de1f90b8fa 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -42,13 +42,10 @@ - if Spree::Config.stripe_connect_enabled = render "shared/stripe_js" - - - if !ContentConfig.open_street_map_enabled - %script{src: "//maps.googleapis.com/maps/api/js?libraries=places,geometry#{ ENV['GOOGLE_MAPS_API_KEY'] ? '&key=' + ENV['GOOGLE_MAPS_API_KEY'] : ''} "} - = javascript_include_tag "darkswarm/all" = javascript_include_tag "web/all" = render "layouts/i18n_script" + = yield :scripts = inject_current_hub diff --git a/app/views/map/index.html.haml b/app/views/map/index.html.haml index c3cb006057..cdbd97de85 100644 --- a/app/views/map/index.html.haml +++ b/app/views/map/index.html.haml @@ -1,6 +1,9 @@ - content_for(:title) do = t :map_title +- content_for :scripts do + = render partial: "shared/google_maps_js" + - content_for :injection_data do = inject_available_countries = inject_enterprise_shopfront_list diff --git a/app/views/producers/index.html.haml b/app/views/producers/index.html.haml index 8a9eec338d..8c0b30246e 100644 --- a/app/views/producers/index.html.haml +++ b/app/views/producers/index.html.haml @@ -1,6 +1,9 @@ - content_for(:title) do = t :producers_title +- content_for :scripts do + = render partial: "shared/google_maps_js" + - content_for :injection_data do - cache @enterprises do = inject_enterprises(@enterprises) diff --git a/app/views/registration/index.html.haml b/app/views/registration/index.html.haml index 5c2e63f0e4..b29e3e8bc3 100644 --- a/app/views/registration/index.html.haml +++ b/app/views/registration/index.html.haml @@ -1,6 +1,9 @@ - content_for(:title) do = t :register_title +- content_for :scripts do + = render partial: "shared/google_maps_js" + - content_for :injection_data do = inject_spree_api_key = inject_available_countries diff --git a/app/views/shared/_google_maps_js.html.haml b/app/views/shared/_google_maps_js.html.haml new file mode 100644 index 0000000000..7772240117 --- /dev/null +++ b/app/views/shared/_google_maps_js.html.haml @@ -0,0 +1,2 @@ +- if !ContentConfig.open_street_map_enabled + %script{src: "//maps.googleapis.com/maps/api/js?libraries=places,geometry#{ ENV['GOOGLE_MAPS_API_KEY'] ? '&key=' + ENV['GOOGLE_MAPS_API_KEY'] : ''} "} diff --git a/app/views/shops/index.html.haml b/app/views/shops/index.html.haml index 845d0a0853..ec5326a319 100644 --- a/app/views/shops/index.html.haml +++ b/app/views/shops/index.html.haml @@ -1,6 +1,9 @@ - content_for(:title) do = t :shops_title +- content_for :scripts do + = render partial: "shared/google_maps_js" + - content_for :injection_data do - cache(*CacheService::FragmentCaching.ams_shops) do = inject_enterprises(@enterprises)