Astro Islands: Beyond Framework Borders

A presentation at EdinburghJS in February 2024 in Edinburgh, UK by Joseph Shambrook

Slide 1

Slide 1

Astro Islands Beyond Framework Borders Joseph Shambrook josephshambrook.dev

Slide 2

Slide 2

Hello! I’m Joe 👋 Senior Developer at KFC 🍗

Slide 3

Slide 3

What’s coming up • 🏝 What are Islands? • 🚀 What is Astro? • 😬 Demo • 👉 Caveats and follow up • 🙋 Q&A

Slide 4

Slide 4

Slide 5

Slide 5

The amount of JavaScript loaded per website has been increasing steadily every year

Slide 6

Slide 6

Mean amount of JS bytes distributed on webpages 600 500 400 300 2019 2020 Desktop 2021 2022 Mobile Figures provided by annual Web Almanac Report

Slide 7

Slide 7

Why is this a bad thing?

Slide 8

Slide 8

• Increased page loading times for downloading and parsing • Blocks rendering of other page content • Higher resource usage

Slide 9

Slide 9

Slide 10

Slide 10

CSR CSR SSG SSR ISR

Slide 11

Slide 11

Client-side rendering Bad (except in a few cases)

Slide 12

Slide 12

Server-side rendering 1 2 3 Page renders pre-built HTML Browser downloads JavaScript and executes React Page is “hydrated” and now interactive

Slide 13

Slide 13

Slide 14

Slide 14

Slide 15

Slide 15

=

! JavaScript “bad”

Slide 16

Slide 16

We as developers need to write and distribute JavaScript responsibly

Slide 17

Slide 17

Slide 18

Slide 18

A principle of f only shipping JavaScript for speci ic components of a webpage

Slide 19

Slide 19

Slide 20

Slide 20

Slide 21

Slide 21

Slide 22

Slide 22

Islands do not depend on each other, but they can share state Custom Events are cool too #UseThePlatform

Slide 23

Slide 23

Only the islands are hydrated, rather than the whole page

Slide 24

Slide 24

Hydrate the whole app ( ) Hydrate bits as needed ( 🏝 )

Slide 25

Slide 25

This lexibility also means f You can load islands dynamically according to requirements

Slide 26

Slide 26

Slide 27

Slide 27

Load this island when the page loads Load this island when we scroll here

Slide 28

Slide 28

Cool 👍

Slide 29

Slide 29

How can I use islands?

Slide 30

Slide 30

Time to introduce Astro

Slide 31

Slide 31

What is Astro? 🚀 • A web framework for creating content-rich websites • Performance at its core • Support for your favourite styling strategies • Huge focus on developer experience

Slide 32

Slide 32

f Astro is server- irst

Slide 33

Slide 33

Astro ships zero JS by default

Slide 34

Slide 34

Use different UI frameworks at the same time

Slide 35

Slide 35

Astro allows you to hydrate islands when needed using “client directives”

Slide 36

Slide 36

<Carousel <Carousel client:load <Carousel client:idle <Carousel client:visible

/

/

/ /

/ <Carousel client:media=”(min-width: 20em)”

Slide 37

Slide 37

<Carousel <Carousel client:load <Carousel client:idle <Carousel client:visible

/

/

/ /

/ <Carousel client:media=”(min-width: 20em)”

Slide 38

Slide 38

<Carousel <Carousel client:load <Carousel client:idle <Carousel client:visible

/

/

/ /

/ <Carousel client:media=”(min-width: 20em)”

Slide 39

Slide 39

<Carousel <Carousel client:load <Carousel client:idle <Carousel client:visible

/

/

/ /

/ <Carousel client:media=”(min-width: 20em)”

Slide 40

Slide 40

<Carousel <Carousel client:load <Carousel client:idle <Carousel client:visible

/

/

/ /

/ <Carousel client:media=”(min-width: 20em)”

Slide 41

Slide 41

Demo 😬

Slide 42

Slide 42

In sum

Slide 43

Slide 43

=

! JavaScript “bad”

Slide 44

Slide 44

Slide 45

Slide 45

Slide 46

Slide 46

What about React Server Components?

Slide 47

Slide 47

Slide 48

Slide 48

Slide 49

Slide 49

Thank you! Questions welcome! But not too many please

Slide 50

Slide 50

Resources • patterns.dev: Documentation on rendering patterns like CSR and SSR • Astro’s own explanation of islands • Deno’s great introduction to islands • My demo on GitHub • Web Almanac’s 2022 state of the web report