devonik / nuxt-3-intercom

6 stars 2 forks source link

Eliminate 128 ms MTB (main-thread blocking) #1

Closed ebrawer closed 1 year ago

ebrawer commented 1 year ago

The widget is currently causing 128 ms of MTB, which really hurts performance on https://pagespeed.web.dev

image

Can the loading be deferred?

devonik commented 1 year ago

Hey, at first thanks for using this :) In my Project I had the same and you will have this even if you natively inject the itercom javascript snippet. The Recommendation to use lazy-loading is a good hint. You can set the module option autoboot to false to prevent that the intercom boot and script injection is loaded at page load. Then you can trigger the intercom boot and also script injection via a custom button event listener

onClick: () => {
          // Intercom lazy loaded
          $intercom.boot({
            custom_launcher_selector: '#mobile-intercom-launcher',
            hide_default_launcher: true,
          })
          setTimeout(() => $intercom.show(), 500)
        },

The setTimeout I had to not to show the intercom chat to early (when the script loading is not finished)

devonik commented 1 year ago

Async is already set. If you have any other good suggestions let me know

devonik commented 1 year ago

Will close this issue cause it can be lazy loaded by call boot() later on. Then async is already set. Feel free to recommend some solution or even contribute :)