- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Live Chat App slows page down
SOLVEFeb 1, 2018 6:14 AM
Hi,
I have the Hubspot Chat installed here:
https://www.3mediaweb.com/great-b2b-software-company-websites/
There is a file:
https://static.hsappstatic.net/conversations-visitor-ui/static-1.383/bundles/visitor.js
which is almost a 1.39 mb file. Is there no way to compress the scripts so it loads faster?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Accepted Solutions
May 19, 2020 2:56 PM
This is for anyone that requested I show our team's workaround for helping page speed with the bloated Live Chat script.
First set the Hubspot chat setting to not immediately load live chat. This single setting alone prevents the "vistor.js" file from loading which appears to be the main contributing file to the slow down. Only allow the live chat to load immediately if you know the user to be in a chat session or if the live chat auto launch hash url is used. (#hs-chat-open)
//Prevent chat from loading immediately load only if chat is not in progress or #hs-chat-open is not in the url if (sessionStorage.getItem("chatInProgress") !== "true" && window.location.hash !== "#hs-chat-open") { window.hsConversationsSettings = { loadImmediately: false }; }
Now that the chat is blocked. We have to artifically create a chat button that will launch live chat only when clicked by the user. The rest of this code will also set a session storage for knowing if the user's conversation is open, which will allow live chat to load itself on page load. There is also observer mutation events to detect when the live chat window is opened, so you can hide the fake hubspot chat button.
if (window.HubSpotConversations) { hubspotChatReady(); } else { window.hsConversationsOnReady = [hubspotChatReady]; } function hubspotChatReady() { //Proceed to immediately load Live Chat while conversation is persisting window.HubSpotConversations.addEventListener("conversationStarted", function () { sessionStorage.setItem("chatInProgress", "true"); }); window.HubSpotConversations.addEventListener("conversationClosed", function () { sessionStorage.removeItem("chatInProgress"); }); //Fake Hubspot Live chat button to launch real live chat only when user clicks //Ignore if Live Chat is already loaded if (window.HubSpotConversations.widget.status().loaded === false) { var $liveChat = document.getElementById("activate-chat"); $liveChat.style.display = "block"; $liveChat.addEventListener("click", function (event) { event.preventDefault(); $liveChat.classList.add("loading"); //Chat window is open when the iframe is loaded in the dom (Hubspot doesn't give a callback for the chat window opening) var observer = new MutationObserver(function (mutationList, observer) { mutationList.forEach(function (m) { m.addedNodes.forEach(function (n) { if (n.id === "hubspot-messages-iframe-container") { n.querySelector('iframe').addEventListener('load', function () { $liveChat.classList.remove("loading"); window.HubSpotConversations.widget.open(); observer.disconnect(); }); } }); }); }); observer.observe(document.body, { childList: true, attributes: false, subtree: false }); window.HubSpotConversations.widget.load({ widgetOpen: true }); }) } }
I hope this helps some people. This is not a perfect workaround. Some of the shortfalls would be if you use Hubspot's "hide launcher" setting. Where maybe you want to turn Live Chat on or off from the portal. This workaround bakes in a fake button that doesn't know if Hubspot chat should or shouldn't be showing. In our situation we leave Live Chat open 24/7 and just use away messages.
We are still waiting for Hubspot to take some concern with page speed. But until then we'll do what we can to work around it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Aug 3, 2020 7:59 PM
Thanks for the codes, it saves my day.
Btw for those who confuse how to create the button, i found another workaround by adding delay. So it will load the chat widget after "X" milliseconds.
Here's the sample code with 15 seconds delay:
<script> window.hsConversationsSettings = { loadImmediately: false }; setTimeout(function() { window.HubSpotConversations.widget.load(); }, 15000); </script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Oct 14, 2020 12:42 PM
Hi all! We recently updated the "Time on page in seconds" trigger. Delaying the chat widget load by at least 5 seconds should optimize for a faster initial page load.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content