Slide 1

Slide 1 text

When in doubt, trust the browser

Slide 2

Slide 2 text

I'm Pieter Beulque Front-end Developer

Slide 3

Slide 3 text

Show what's possible without the trusted npm install Goal of today

Slide 4

Slide 4 text

Let's build a tweet embed

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Let's start!

Slide 9

Slide 9 text

Custom Elements Defining a re-usable component

Slide 10

Slide 10 text

Custom Elements Create your own Progressive enhancement dream Initializes whenever a node is added to the DOM Anything is possible!

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Custom Elements There's a very good introduction on Google Developers' Web Fundamentals

Slide 15

Slide 15 text

Shadow DOM King of the castle

Slide 16

Slide 16 text

Shadow DOM Isolate component's DOM Scope component styles

Slide 17

Slide 17 text

Shadow DOM Isolate component's DOM Scope component styles

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Also Also

Slide 24

Slide 24 text

Shadow DOM :host & ::slotted()

Slide 25

Slide 25 text

Shadow DOM :host

Slide 26

Slide 26 text

Shadow DOM

Slide 27

Slide 27 text

Shadow DOM

Slide 28

Slide 28 text

Shadow DOM There's another very good introduction on Google Developers' Web Fundamentals

Slide 29

Slide 29 text

Browser support Both can be polyfilled: github.com/webcomponents/polyfills All evergreen browsers Edge starting January 2020 No Internet Explorer

Slide 30

Slide 30 text

Use it in production?

Slide 31

Slide 31 text

Custom Elements Yes, but… Have been using it for 3 years Has its limitations Wouldn't use it for applications

Slide 32

Slide 32 text

Shadow DOM You could, but… Falls short compared to frameworks Feels clunky

Slide 33

Slide 33 text

My thoughts Great to sprinkle Javascript on top of content websites More accessible out of the box than a everything-in-JS approach Probably run into limits when using for applications

Slide 34

Slide 34 text

North star Custom Elements as a compile target ✨ Stencil & Svelte already support this.

Slide 35

Slide 35 text

Let's move on

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

Internationalization API Intl.RelativeTimeFormat

Slide 39

Slide 39 text

Internationalization API Format dates, numbers and plurals The browser already has all languages Your browser knows your user's preferences

Slide 40

Slide 40 text

Internationalization API new Intl.RelativeTimeFormat( 'en', ).format( value, unit )

Slide 41

Slide 41 text

Internationalization API new Intl.RelativeTimeFormat( 'en', // Any valid locale ).format( value, // A number, positive = future, negative = past unit // 'months', 'days', 'years', … )

Slide 42

Slide 42 text

Internationalization API new Intl.RelativeTimeFormat('en').format(1, 'day') in 1 day new Intl.RelativeTimeFormat('nl').format(-1, 'year') 1 jaar geleden new Intl.RelativeTimeFormat('fr').format(0, 'month') dans 0 mois

Slide 43

Slide 43 text

That's not very human new Intl.RelativeTimeFormat('en').format(1, 'day') in 1 day new Intl.RelativeTimeFormat('fr').format(0, 'month') dans 0 mois

Slide 44

Slide 44 text

That's not very human new Intl.RelativeTimeFormat( 'en', { numeric: 'auto' } ).format(1, 'day') tomorrow ce mois-ci new Intl.RelativeTimeFormat( 'fr', { numeric: 'auto' } ).format(0, 'month')

Slide 45

Slide 45 text

Browser support There's a polyfill from Polyfill.io: github.com/andyearnshaw/Intl.js/ Chrome, Firefox and Opera No Safari No Edge or Internet Explorer

Slide 46

Slide 46 text

Use it in production?

Slide 47

Slide 47 text

Internalization API Definitely! Save bandwidth on translation files All edge cases handled automatically Locale 'default' uses your user's preferences

Slide 48

Slide 48 text

1 + 1 = 2 Let's recap

Slide 49

Slide 49 text

Let's build a reusable, standalone component that turns a time into a human-readable, relative time

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

No content

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

Define attributes to watch for changes Run the formatter on every change

Slide 57

Slide 57 text

Define attributes to watch for changes Run the formatter on every change

Slide 58

Slide 58 text

Zero dependencies. Self-contained. Re-usable. 20 LOC.

Slide 59

Slide 59 text

OK, I cheated a little. The code that calculates the date difference adds another 30 lines.

Slide 60

Slide 60 text

All in a single file?

Slide 61

Slide 61 text

ES Modules Do you really need a bundler?

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

No content

Slide 64

Slide 64 text

The browser knows what to do.

Slide 65

Slide 65 text

Browser support Everywhere but IE & UC Browser Serve bundle as a fallback, thanks to nomodule

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

Progressive Enhancement is beautiful And browsers are amazingly good at it.

Slide 68

Slide 68 text

Use it in production?

Slide 69

Slide 69 text

ES Modules Yes, with caution Definitely needs HTTP/2 No problem for small amount of modules Watch out for huge dependency trees

Slide 70

Slide 70 text

North star ES Modules as a bundling target ✨ Rollup & Parcel already support this.

Slide 71

Slide 71 text

One more thing

Slide 72

Slide 72 text

Built-in lazy loading Unofficial, Chrome-only

Slide 73

Slide 73 text

So remember…

Slide 74

Slide 74 text

When in doubt, trust the browser

Slide 75

Slide 75 text

Thank you! Questions? @pieterbeulque