From 0a08e1ffc0640ef6ff43b34ccb0754e573ce040b Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Date: Thu, 26 Aug 2021 19:51:10 +0530 Subject: [PATCH] feat: Adds async and defer attributes to chatwoot script tag (#2890) Co-authored-by: Muhsin Keloth Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> --- Gemfile.lock | 1 + app/models/channel/web_widget.rb | 2 ++ app/views/layouts/vueapp.html.erb | 2 ++ app/views/widget_tests/index.html.erb | 2 ++ 4 files changed, 7 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 6dbb389ec..c11e09a14 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -630,6 +630,7 @@ GEM PLATFORMS arm64-darwin-20 + x86_64-darwin-20 x86_64-darwin-21 x86_64-linux diff --git a/app/models/channel/web_widget.rb b/app/models/channel/web_widget.rb index 591efcaab..02b85f75a 100644 --- a/app/models/channel/web_widget.rb +++ b/app/models/channel/web_widget.rb @@ -59,6 +59,8 @@ class Channel::WebWidget < ApplicationRecord var BASE_URL=\"#{ENV.fetch('FRONTEND_URL', '')}\"; var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; g.src=BASE_URL+\"/packs/js/sdk.js\"; + g.defer = true; + g.async = true; s.parentNode.insertBefore(g,s); g.onload=function(){ window.chatwootSDK.run({ diff --git a/app/views/layouts/vueapp.html.erb b/app/views/layouts/vueapp.html.erb index b9350e3b9..621c62029 100644 --- a/app/views/layouts/vueapp.html.erb +++ b/app/views/layouts/vueapp.html.erb @@ -66,6 +66,8 @@ var BASE_URL=""; var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; g.src=BASE_URL+"/packs/js/sdk.js"; + g.defer = true; + g.async = true; s.parentNode.insertBefore(g,s); s.async=!0; g.onload=function(){ diff --git a/app/views/widget_tests/index.html.erb b/app/views/widget_tests/index.html.erb index 78dbaa37c..c1de883ee 100644 --- a/app/views/widget_tests/index.html.erb +++ b/app/views/widget_tests/index.html.erb @@ -24,6 +24,8 @@ window.chatwootSettings = { var BASE_URL = ''; var g=d.createElement(t),s=d.getElementsByTagName(t)[0]; g.src= BASE_URL + "/packs/js/sdk.js"; + g.defer = true; + g.async = true; s.parentNode.insertBefore(g,s); g.onload=function(){ window.chatwootSDK.run({