Mark Ku's Blog

Don't Let Third-Party JS Slow Down Your Homepage Load Time - Notes on Optimizing Facebook Chat SDK Integration

The Problem

Many websites integrate third-party JS. After integrating the Facebook Chat SDK on one occasion, I noticed the homepage became extremely slow to load, so I decided to optimize it. Facebook Messenger chat widget with login options

As a software developer, I opened up the developer tools and made a comparison.

In the Network tab, we can see the files coming from fbcdn. I discovered they accounted for 1.8 MB of network traffic, with an uncompressed size of 7.2 MB. I thought to myself, "This is way too bloated; no wonder it's so slow." Network tab showing 1.8MB transferred and 7.2MB total resources

  • Additional note: "transferred over network" is the size of the resources loaded over the network, while "resources loaded by the page" is the original size of all resources after they have been uncompressed by the browser.

Optimization Steps

The initial load for an SPA is already quite large. To avoid negatively impacting the user experience, I considered adding a button to load the chat system on-demand. However, I still felt the SDK was too bloated. Ultimately, I decided to create a simple customer service button that links directly to Facebook Messenger.

1. First, get your Messenger URL from your Page > Settings > Messaging

Facebook Page Settings Messaging tab showing Messenger URL
Facebook Page Settings Messaging tab showing Messenger URL

2. Encapsulate it in a component

<template>
   <a href="https://m.me/letsgogofruit" target="_bank">
      <div class="facebook-live-chat">
        <SvgIcon icon-name="messenger" class="w-52 h-52" />
      </div>
    </a>
</template>

<style lang="scss">
.facebook-live-chat{
  position: fixed;
  right: 30px;
  bottom: 160px;
  z-index: 8;
  border: none;
  border-radius: 100%;  
  
  font-size: 22px;
  text-align: center;
  // display: none;  
  cursor: pointer;

  svg{
    &:hover{
      filter: drop-shadow(0 0 2px rgba(#fff, 0.5));
    }
  }

  @media (max-width: 577px) {
    
      svg{
        width: 40px;
        height:40px;
      }  
      right:20px;  
      // bottom: 130px;
      //  解決 ios tab bar 問題
    // iOS < 11.2
    bottom: calc(172px + constant(safe-area-inset-bottom));

    // iOS >= 11.2
    bottom:calc(172px + env(safe-area-inset-bottom));
    }  
}

</style>

Results

Website homepage displaying three article placeholders and a footer
Website homepage displaying three article placeholders and a footer
Mobile article page in browser with image placeholder and chat icon
Mobile article page in browser with image placeholder and chat icon

Author

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··602

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··490

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··333

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··264

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··221

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··215

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11