Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
React in a worker, worker, worker...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
stefan judis
May 23, 2019
Technology
600
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
React in a worker, worker, worker...
stefan judis
May 23, 2019
More Decks by stefan judis
See All by stefan judis
Back to boring (part 2)
stefanjudis
0
370
Playwright can do this?
stefanjudis
0
240
Things you should know about Frontend Development in 2022
stefanjudis
0
560
Throw yourself out there for fun and profit
stefanjudis
0
140
Back to Boring
stefanjudis
1
530
Wanna scale up? Make sure your CMS is ready for it!
stefanjudis
0
280
Did we(b development) lose the right direction?
stefanjudis
6
2.2k
Regular expressions – my secret love
stefanjudis
1
1.1k
Write a Function
stefanjudis
0
620
Other Decks in Technology
See All in Technology
「ビジネスがわかるエンジニア」とは何か?
ryooob
0
420
Multi-Agent並列開発を 安全に回すための技術 / Technology for Safely Multi-Agent Parallel Development
tooppoo
0
230
事業会社は今こそSWEを高給で雇ってWebシステムを内製しよう
masaokb
0
110
AWS Summit Japan 2026の振り返りと2027へ向けて / AWS Summit Japan 2026 Recap and Prospects for 2027
kaminashi
1
130
コミュニティの有益性 ~JAWS Days 2026 での体験を通して~ / The Benefits of a Community ~Through My Experience at JAWS Days 2026~
seike460
PRO
0
310
CVE-2026-20833_脆弱性対応とAES 化について
jukishiya
0
290
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.2k
product engineering with qa
nealle
0
100
起点・思考・出力で分解する 〜PM業務の自動化設計〜
kazu_kichi_67
2
1.2k
從觀望到全公司落地:AI Agentic Coding 導入實戰 — 流程整合與安全治理
appleboy
0
260
小さいから、全部わかる。— 常駐AI "xangi" のすすめ
sugupoko
0
190
そこにあるから地図ができる~位置を示す"モノ"を愉しむ~ - Interface 2026年6月号GPS特集オフ会 / interface_202606_GPS_offline
sakaik
1
140
Featured
See All Featured
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
360
Everyday Curiosity
cassininazir
0
240
A Soul's Torment
seathinner
6
3k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
350
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
490
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
310
The Curious Case for Waylosing
cassininazir
1
410
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
ラッコキーワード サービス紹介資料
rakko
1
3.8M
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
240
Designing for Performance
lara
611
70k
It's Worth the Effort
3n
188
29k
Transcript
@stefanjudis React in a worker, worker, worker, worker...
@stefanjudis www.stefanjudis.com Heyo, I'm Stefan!
Let's talk about CRA (create-react-app)
None
A classical Single Page App
There are problems with typical single page apps...
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="shortcut
icon" href="/favicon.ico" /> <meta name="viewport" content="[ ...]" /> <meta name="theme-color" content="#000000" /> <link rel="manifest" href="/manifest.json" /> <title>React App </title> </head> <body> <noscript>No JavaScriptzzzz ... </noscript> <div id="root"> </div> <script src="/static/js/bundle.js"> </script> <script src="/static/js/0.chunk.js"> </script> <script src="/static/js/main.chunk.js"> </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="shortcut
icon" href="/favicon.ico" /> <meta name="viewport" content="[ ...]" /> <meta name="theme-color" content="#000000" /> <link rel="manifest" href="/manifest.json" /> <title>React App </title> </head> <body> <noscript>No JavaScriptzzzz ... </noscript> <div id="root"> </div> <script src="/static/js/bundle.js"> </script> <script src="/static/js/0.chunk.js"> </script> <script src="/static/js/main.chunk.js"> </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="shortcut
icon" href="/favicon.ico" /> <meta name="viewport" content="[ ...]" /> <meta name="theme-color" content="#000000" /> <link rel="manifest" href="/manifest.json" /> <title>React App </title> </head> <body> <noscript>No JavaScriptzzzz ... </noscript> <div id="root"> </div> <script src="/static/js/bundle.js"> </script> <script src="/static/js/0.chunk.js"> </script> <script src="/static/js/main.chunk.js"> </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="shortcut
icon" href="/favicon.ico" /> <meta name="viewport" content="[ ...]" /> <meta name="theme-color" content="#000000" /> <link rel="manifest" href="/manifest.json" /> <title>React App </title> </head> <body> <noscript>No JavaScriptzzzz ... </noscript> <div id="root"> </div> <script src="/static/js/bundle.js"> </script> <script src="/static/js/0.chunk.js"> </script> <script src="/static/js/main.chunk.js"> </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="shortcut
icon" href="/favicon.ico" /> <meta name="viewport" content="[ ...]" /> <meta name="theme-color" content="#000000" /> <link rel="manifest" href="/manifest.json" /> <title>React App </title> </head> <body> <noscript>No JavaScriptzzzz ... </noscript> <div id="root"> </div> <script src="/static/js/bundle.js"> </script> <script src="/static/js/0.chunk.js"> </script> <script src="/static/js/main.chunk.js"> </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="shortcut
icon" href="/favicon.ico" /> <meta name="viewport" content="[ ...]" /> <meta name="theme-color" content="#000000" /> <link rel="manifest" href="/manifest.json" /> <title>React App </title> </head> <body> <noscript>No JavaScriptzzzz ... </noscript> <div id="root"> </div> <script src="/static/js/bundle.js"> </script> <script src="/static/js/0.chunk.js"> </script> <script src="/static/js/main.chunk.js"> </script> </body> </html> No JavaScript zzzz ...
13 Million requests for JavaScript will time out. Ian Feather
(Buzzfeed)
"We don't have any non- JavaScript users". No, all your
users are non-JS while they're downloading your JS. Jake Archibald (Google)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="shortcut
icon" href="/favicon.ico" /> <meta name="viewport" content="[ ...]" /> <meta name="theme-color" content="#000000" /> <link rel="manifest" href="/manifest.json" /> <title>React App </title> </head> <body> <noscript>No JavaScriptzzzz ... </noscript> <div id="root"> </div> <script src="/static/js/bundle.js"> </script> <script src="/static/js/0.chunk.js"> </script> <script src="/static/js/main.chunk.js"> </script> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="shortcut
icon" href="/favicon.ico" /> <meta name="viewport" content="[ ...]" /> <meta name="theme-color" content="#000000" /> <link rel="manifest" href="/manifest.json" /> <title>React App </title> </head> <body> <noscript>No JavaScriptzzzz ... </noscript> <div id="root"> </div> <script src="/static/js/bundle.js"> </script> <script src="/static/js/0.chunk.js"> </script> <script src="/static/js/main.chunk.js"> </script> </body> </html> The spinner of death
How can we do better?
proxx.app
nextjs.org www.gatsbyjs.org
nextjs.org www.gatsbyjs.org Run the same React code on the server
and client
None
None
None
None
bundle.js
bundle.js
bundle.js Interactive
Better performance!
Better performance! Faster indexed by Google!
Better performance! Faster indexed by Google! It's the same code
front to back!
But is it really the same code?
module.exports = global.fetch = global.fetch || (typeof process == 'undefined'
? require('unfetch').default || require('unfetch') : function(url, opts) { return require('node-fetch')(url.replace(/^\/\ //g, 'https: //'), opts); });
github.com/developit/unfetch/tree/master/packages/isomorphic-unfetch
What if we serve HTML from an environment with the
same methods?
The Service Worker worker.js
if ('serviceWorker' in navigator) { navigator.serviceWorker .register('/worker.js') .then(function(registration) {}, function(err)
{}); }
self.addEventListener('fetch', function(event) { event.respondWith( caches.match(event.request) .then(function(response) { // Cache hit
- return response if (response) { return response; } return fetch(event.request); } ) ); });
Let's try an experiment?
Crowd Coding...
What did just happen?
None
localhost:8080
localhost:8080
localhost:8080 worker.js
localhost:8080 worker.js
localhost:8080 worker.js Interactive
localhost:8080 worker.js Interactive
localhost:8080 worker.js Interactive
localhost:8080 worker.js Interactive
localhost:8080 worker.js Interactive
localhost:8080 worker.js Interactive
worker.js
worker.js
worker.js
worker.js
Could universal workers be a thing?
Let's create a cloud worker!
www.cloudflare.com/products/cloudflare-workers/
developers.cloudflare.com/workers/reference/
developers.cloudflare.com/workers/reference/
developers.cloudflare.com/workers/reference/
https://dash.cloudflare.com/9dcd7c...
worker.js
worker.js
worker.js
worker.js
worker.js
worker.js
worker.js
worker.js
worker.js worker.js
worker.js worker.js
worker.js worker.js
worker.js
worker.js
worker.js
worker.js
worker.js
Is this the solution to universal JavaScript?
Service worker development is still very tedious
Cache handling is tough
It's worth investigating!
Servers with browser APIs will change how we share code!
react-in-a-worker.netlify.com
www.react-in-a-worker.rocks
github.com/stefanjudis/react-in-a-worker
One last thing...
... let's serve HTML instead of spinners.
@stefanjudis
[email protected]
www.stefanjudis.com Thanks.