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
選擇 Svelte 的三個理由 - JSDC
Search
Kalan
October 30, 2021
Technology
410
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
選擇 Svelte 的三個理由 - JSDC
Kalan
October 30, 2021
More Decks by Kalan
See All by Kalan
單頁式應用中的無障礙設計
kjj6198
0
830
Svelte - 如何在前端框架中脫穎而出 | ModernWeb'21
kjj6198
0
220
状態管理を楽にする道
kjj6198
1
430
Day25. 如何解析 HTML 語法
kjj6198
0
190
Day24. Svelte 如何編譯程式碼(2)
kjj6198
0
230
Svelte 如何編譯程式碼(1)
kjj6198
0
240
Day22. Svelte 經驗談
kjj6198
0
220
Day18. UI 實戰篇 - 圖片檢視器
kjj6198
0
210
Day17. UI 實戰篇 - 音樂播放器
kjj6198
0
110
Other Decks in Technology
See All in Technology
徹底討論!ECS vs EKS!
daitak
3
1.8k
Kotlin 開発のツラミを爆破した話! / Explode the difficulty of Kotlin dev!
eller86
0
130
4人目のSREはAgent
tanimuyk
0
320
AWS Security Hub CSPMの成功・失敗体験
cmusudakeisuke
0
620
コミュニティの有益性 ~JAWS Days 2026 での体験を通して~ / The Benefits of a Community ~Through My Experience at JAWS Days 2026~
seike460
PRO
0
310
Agentic AI 時代のテスト手法: Kiro とはじめるプロパティベーステスト (AWS Summit Japan 2026 | DEV212)
ymhiroki
0
140
MySQL & MySQL HeatWave Report - June 2026
freshdaz
0
250
本当の”仕事”を手放せる未来が見えた
mu7889yoon
0
210
WebGIS AI Agentの紹介
_shimizu
0
600
はてなのサービス基盤を支える Kubernetes《足腰》
masayoshimaezawa
0
380
グローバルチームと挑むプロダクト開発
sansantech
PRO
1
110
“詰む”前に仕組みを作れ 〜技術の波に溺れないためのキャッチアップ術〜
takasyou
8
4.7k
Featured
See All Featured
The Mindset for Success: Future Career Progression
greggifford
PRO
0
370
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
260
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
410
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
220
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
The Curious Case for Waylosing
cassininazir
1
410
How to train your dragon (web standard)
notwaldorf
97
6.7k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
290
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
Transcript
選擇 Svelte 的三個理由 Kalan JSDC 2021 1
⾃我介紹 2 • Kalan (愷開) • Frontend Engineer@LINE Fukuoka •
blog.kalan.dev • @kjj6198 • @kalanyei
Svelte 是什麼 • ⼀⾨前端框架 • 由 Rich Harris 在 2016
年開始開發 • 透過事先編譯的⽅式減少 runtime 體積 • 400 多位貢獻者 3
當然,你也可以來貢獻 https://github.com/sveltejs/svelte/pull/4733 4
Agenda • 簡介 Svelte • 現代前端框架的基本要素 • 選擇 Svelte 的三個理由
• 語法簡單、容易上⼿ • bundle size 體積⼩ • 關注度持續提升
框架好多,我快學不動了 • 框架的出現代表開發者對現況的不滿 • ⼈們對於最佳實踐的探索 6
「現代」前端框架的基本要素 • 元件化的中⼼思想 7 / / js function as component
export const Profile = ({ user }) = > { return <div>{user.name} < / div>; }; < ! - - SFC - - > <template> <div>{{ user.name }} < / div> < / templte>
「現代」前端框架的基本要素 • 元件化的中⼼思想 • 響應機制(Reactivity) 8 <script setup> import {
ref } from 'vue' const count = ref(0) < / script> <template> <button @click="count + + ">{{ count }} < / button> < / template> export const Profile = () = > { const [user, setUser] = useState({ name: "kalan" }); return <button onClick={() = > setUser({ name: 'hoge' })}> {user.name} < / button>; };
「現代」前端框架的基本要素 • 元件化的中⼼思想 • 響應機制(Reactivity) • ⽣命週期 9 <script> export
default { mounted() { . . . } } < / script> <template> <div> < / div> < / template> export const Profile = () = > { useEffect(() = > { . . . }, []); useEffect(() = > { . . . }, [deps]); return <div> . . . < / div>; };
問題點 • 需要在 runtime 做 di ff 演算 → 增加
bundle size • 需要實作⼀套響應機制 → 犧牲⼀部分的效能 10
理由⼀:語法簡單、容易上⼿ 會寫 HTML、JavaScript、CSS 就可以寫 Svelte
Svelte 如何簡化 事先編譯並⽣成 JavaScript 程式碼 12 / / Countdown.svelte <script>
let countdown = 10; onMount(() = > { setInterval(() = > countdown -= 1, 1000); }) < / script> <span>{countdown} < / span>
Svelte 如何簡化 事先編譯並⽣成 JavaScript 程式碼 13 <script> let countdown =
10; onMount(() = > { setInterval(() = > countdown -= 1, 1000); }) < / script> <span>{countdown} < / span>
Tweet: twitter.com/AdamRackis/status/1438221959029039108 14
響應式語法 15 <script> import { onMount } from 'svelte'; let
countdown = 80; $: formatted = `${format(countdown, 'xx:xx')}`; onMount(() = > { setInterval(() = > countdown -= 1, 1000) }); < / script> <span>{formatted} < / span>
樣板語法 16 <script> export let age = 16; const handleClick
= () = > age + + ; < / script> <button on:click={handleClick}>長⼀歲 < / button> {#if age > = 18} <span>已成年 < / span> {:else} <span>未成年 < / span> {/if}
線上 REPL 與互動式教學 可以直接在網⾴上寫程式碼看效果 17
理由⼆:Bundle size 體積⼩ 善⽤編譯機制
編譯器的好處 • 不會影響 runtime 體積 • 可以進⾏靜態分析(變數追蹤、優化) • 優化⽣成程式碼 •
去除未使⽤的程式碼片段 Bundle size 變得更⼩!
None
• 只會引入必要的依賴 • 編譯後會變為 DOM API 呼叫 • 在 runtime
沒有 virtual DOM 和 di ff 機制 注意:Svelte 不是 zero-runtime
• name2 在畫⾯中未使⽤ • 因此不安排元件更新
分享:動物森友會情報表 JS bundle size: 10.6KB (gzip)
分享:台灣性侵害事件統計 JS bundle size: 49.6KB (gzip)
專案分享:⽇語八百屋 JS bundle size: 20.2KB (gzip)
關於 Bundle size • bundle size 是⼀種預算 • 不是每個專案都要變成獨⾓獸
理由三:關注度持續上升 開發者與社群的反應可當作指標參考
State of JS 2020 滿意度第⼀名 28
State of JS 2020 使⽤情形 29
Stack Overflow Survey 2021 最受喜愛的網⾴框架 30
有使⽤ Svelte 的公司 https://svelte.dev 31
分享:美國總統⼤選開票 • 關鍵評論網:Svelte • 天下雜誌:Svelte • Bloomberg:Svelte 32 截圖為 bloomberg
台灣 • 相比國外社群比較不熱絡 • 網路上的資源相對較少 33
缺點 • ⼤多數的處理都在編譯時期 • 相對其他框架資源較少 • 使⽤率仍然偏低 34
寫在最後 加入 Facebook 社團 Svelte.js Taiwan!