From a98e4417c0519d8596ad0584e2eade2045536dc9 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 16 Aug 2021 13:19:23 +0100 Subject: [PATCH 1/2] Only inject taxons and properties AMS data in pages where it's actually needed --- app/views/enterprises/shop.html.haml | 4 ++++ app/views/groups/show.html.haml | 4 ++++ app/views/layouts/darkswarm.html.haml | 4 ---- app/views/map/index.html.haml | 4 ++++ app/views/producers/index.html.haml | 4 ++++ app/views/shops/index.html.haml | 4 ++++ 6 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/views/enterprises/shop.html.haml b/app/views/enterprises/shop.html.haml index 3008b50d49..150452a4e9 100644 --- a/app/views/enterprises/shop.html.haml +++ b/app/views/enterprises/shop.html.haml @@ -8,6 +8,10 @@ - content_for :injection_data do - cache(*CacheService::FragmentCaching.ams_shop(@enterprise)) do = inject_enterprise_shopfront(@enterprise) + - cache(*CacheService::FragmentCaching.ams_all_taxons) do + = inject_taxons + - cache(*CacheService::FragmentCaching.ams_all_properties) do + = inject_properties %shop.darkswarm - if @shopfront_layout == 'embedded' diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml index b5622063a2..df1152bd70 100644 --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -9,6 +9,10 @@ = inject_available_countries = inject_group_enterprises = inject_open_street_map_config + - cache(*CacheService::FragmentCaching.ams_all_taxons) do + = inject_taxons + - cache(*CacheService::FragmentCaching.ams_all_properties) do + = inject_properties #group-page.row.pad-top.footer-pad{"ng-controller" => "GroupPageCtrl"} .small-12.columns.pad-top diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index e745a20b3c..82c36ee492 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -54,10 +54,6 @@ = inject_current_hub = inject_current_user = inject_rails_flash - - cache(*CacheService::FragmentCaching.ams_all_taxons) do - = inject_taxons - - cache(*CacheService::FragmentCaching.ams_all_properties) do - = inject_properties = inject_current_order = inject_currency_config = yield :injection_data diff --git a/app/views/map/index.html.haml b/app/views/map/index.html.haml index 42b0000d19..c3cb006057 100644 --- a/app/views/map/index.html.haml +++ b/app/views/map/index.html.haml @@ -5,5 +5,9 @@ = inject_available_countries = inject_enterprise_shopfront_list = inject_open_street_map_config + - cache(*CacheService::FragmentCaching.ams_all_taxons) do + = inject_taxons + - cache(*CacheService::FragmentCaching.ams_all_properties) do + = inject_properties = render partial: "shared/map" diff --git a/app/views/producers/index.html.haml b/app/views/producers/index.html.haml index b00268066b..8a9eec338d 100644 --- a/app/views/producers/index.html.haml +++ b/app/views/producers/index.html.haml @@ -4,6 +4,10 @@ - content_for :injection_data do - cache @enterprises do = inject_enterprises(@enterprises) + - cache(*CacheService::FragmentCaching.ams_all_taxons) do + = inject_taxons + - cache(*CacheService::FragmentCaching.ams_all_properties) do + = inject_properties .producers{"ng-controller" => "EnterprisesCtrl", "ng-cloak" => true} .row diff --git a/app/views/shops/index.html.haml b/app/views/shops/index.html.haml index 032096ebb9..845d0a0853 100644 --- a/app/views/shops/index.html.haml +++ b/app/views/shops/index.html.haml @@ -4,6 +4,10 @@ - content_for :injection_data do - cache(*CacheService::FragmentCaching.ams_shops) do = inject_enterprises(@enterprises) + - cache(*CacheService::FragmentCaching.ams_all_taxons) do + = inject_taxons + - cache(*CacheService::FragmentCaching.ams_all_properties) do + = inject_properties #panes #shops.pane 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 2/2] 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)