
許多網站都會串接第三方的JS,但在某次串接完 Facebook Chat SDK 後,發現首頁的載入變得非常的慢,並決定著手優化。
 
  
從 Network Tab 中,我們可以得知來自 fbcdn 的檔案,發現就有1.8 mb 網路流量,解壓縮後的檔案大小為7.2 mb,心想這未免也太肥大,難怪會慢。

SPA 網頁本身首次載入就很肥大,為了避免影響用戶體驗,雖然我也可以做個按鈕,按下才開始載入客服系統,但我覺得還是太肥大了,最後我決定做一個客服按鈕,直接開啟 Facebook 的連結。

<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>

