Late to the party

A presentation at Hyvä Meetup in March 2023 in Rodenrijs, 2651 BT Berkel en Rodenrijs, Netherlands by Edwin Bos

Slide 1

Slide 1

Late to the party Everything about loading third-party scripts

Slide 2

Slide 2

Edwin Bos Lead Front-End @ Cream

Slide 3

Slide 3

Late to the party Everything about loading third-party scripts, like: • • • • • • • conversion trackers visitor behaviour trackers chat widgets YouTube video’s Tag Manager analytics etc.

Slide 4

Slide 4

Late to the party Everything about loading third-party scripts, like: • • • • • • • conversion trackers visitor behaviour trackers chat widgets YouTube video’s Tag Manager analytics etc.

Slide 5

Slide 5

Why performance matter A one-second delay in mobile load times can impact conversion rates by up to 20% * Back in 2006, Amazon found that every 100ms in added page load time cost them 1% in sales **

  • Source: SOASTA,The State of Online Retail Performance, U.S., April 2017. ** http://glinden.blogspot.com/2006/11/marissa-mayer-at-web-20.html

Slide 6

Slide 6

Why performance matter If a slow experience drives customers away, a fast experience can help attract and keep them

Slide 7

Slide 7

Is 100 points at pagespeed the ultimate goal?

Slide 8

Slide 8

Is 100 points at pagespeed the ultimate goal? Pagespeed Insights a good starting point Better insight with Devtools and tools like WebPageTest

Slide 9

Slide 9

The waterfall

Slide 10

Slide 10

But first the low hanging fruits Scripts in tag manager from old site Scripts that are loaded without a subscription Script that do something, but no important for the business Use native functionalities, like the Share API

Slide 11

Slide 11

Use alternative script Load YouTube with Lite YouTube Embed, 224x faster https://github.com/paulirish/lite-youtube-embed Load Google Analytics 4 with Minimal Analytics 4, just 2kb https://gist.github.com/idarek/9ade69ac2a2ef00d98ab950426af5791?s=09

Slide 12

Slide 12

Avoid render blocking resources

Slide 13

Slide 13

Avoid render blocking resources

Slide 14

Slide 14

Avoid render blocking resources

Slide 15

Slide 15

Avoid render blocking resources

Slide 16

Slide 16

Adobe Typekit example

Slide 17

Slide 17

Preconnect & Prefetch

Slide 18

Slide 18

Pre-connect & Pre-fetch

Slide 19

Slide 19

Host third-party scripts locally This makes a third-party script a rst-party script You can re-download the script every night if they change a lot fi Google Fonts is the best example (but not a script)

Slide 20

Slide 20

Load Tag Manager or scripts on user interaction You can load Tag Manager on rst interaction fi Or set an event for user interaction

Slide 21

Slide 21

Load Tag Manager on user interaction The moment the user has its rst interaction, the JavaScript get loaded. A user interaction is: Touchstart mouseover, wheel scroll keydown fi • • • • •

Slide 22

Slide 22

Load Tag Manager on user interaction

Slide 23

Slide 23

Load Tag Manager on user interaction

Slide 24

Slide 24

Load Tag Manager on user interaction

Slide 25

Slide 25

Load Tag Manager on user interaction

  • Source: https://docs.hyva.io/hyva-themes/writing-code/patterns/loading-external-javascript.html

Slide 26

Slide 26

Load Tag Manager on user interaction

  • Source: https://docs.hyva.io/hyva-themes/writing-code/patterns/loading-external-javascript.html

Slide 27

Slide 27

Load Tag Manager on user interaction

  • Source: https://docs.hyva.io/hyva-themes/writing-code/patterns/loading-external-javascript.html

Slide 28

Slide 28

Set trigger for user interaction

Slide 29

Slide 29

Set trigger for user interaction

Slide 30

Slide 30

Set trigger for user interaction

Slide 31

Slide 31

Set trigger for user interaction

Slide 32

Slide 32

Set trigger for user interaction

Slide 33

Slide 33

Set trigger for user interaction

Slide 34

Slide 34

Load other script on user interaction For example TrustedShops

Slide 35

Slide 35

Load other script on user interaction

Slide 36

Slide 36

Load other script on user interaction

Slide 37

Slide 37

Load chat widget on click How many people do use the chat? Chat widgets are large (500kb - 1MB), created in React or other libraries Load it on click on fake button

Slide 38

Slide 38

Partytown (beta) Get third-party script of the main thread https://partytown.builder.io/

Slide 39

Slide 39

Partytown

Slide 40

Slide 40

Partytown

Slide 41

Slide 41

Client side GTM vs. Server side GTM

Slide 42

Slide 42

GTM server side Browser-based tracking and cookies won’t last long server-side tracking is the future fi It can make third-party script, rst-party scripts

Slide 43

Slide 43

GTM server side Only for tracking, analytics, marketing code You still have scripts that needs JavaScript client side It can get expensive (especially if you’re doing it wrong) Server-side tracking can get very technical, very fast

Slide 44

Slide 44

This is the end, beautiful friend Questions ???

Slide 45

Slide 45

This is the end, beautiful friend https://twitter.com/edwinbos1

Slide 46

Slide 46

Thanks for watching