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
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
360
Playwright can do this?
stefanjudis
0
240
Things you should know about Frontend Development in 2022
stefanjudis
0
550
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
RAG を使わないという選択肢
tatsutaka
1
250
エンジニアリング戦略の作り方 / Crafting Engineering Strategy
iwashi86
21
7k
AIソロプレナー時代に2ヶ月で20人増員した事業創造会社の開発組織の話
miyatakoji
0
670
非エンジニアがClaudeと挑んだ「1ヶ月間プロダクト30本ノック」
askokc
0
570
作って終わりにしない タイミーのセマンティックレイヤー育成の現在地
chanyou0311
4
2.4k
LayerX コーポレートエンジニアリング室におけるサプライチェーンセキュリティへの取り組み / Supply Chain Security at LayerX Corporate Engineering
yuyatakeyama
2
590
脆弱性対応、どこで線を引くか
rymiyamoto
1
400
不要なレビューをAIにまかせて AIコーディングの環境改善を加速した
shoota
1
150
アジャイルな経理と Claude Code と経営の未来
kawaguti
PRO
3
120
Claude Codeとのおしゃべりでセマンティックモデルの定義からダッシュボード作成まで完成させる
nic_sugiyama
0
120
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
4
3k
AIっぽい文章を採点して人間らしく直すアプリを作ってみた
yama3133
2
200
Featured
See All Featured
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
210
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
540
Navigating Team Friction
lara
192
16k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
300
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
470
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.