Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Optimize JavaScript execution and parse time us...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
chph
September 30, 2016
Technology
170
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Optimize JavaScript execution and parse time using optimize-js
chph
September 30, 2016
More Decks by chph
See All by chph
Chrome Dev Tools 基礎技巧
chph
0
100
DevOpsDays Taipei 2017 敏捷思維分享
chph
0
120
在 Google Cloud Platform 架設你的網站伺服器並撰寫 Node.js 應用程式
chph
0
720
Intro to Progressive Web Apps
chph
1
78
淺談 Gzip
chph
0
140
Install WordPress on Linode
chph
0
170
Introduction Infrastructure - Linode 入門
chph
0
240
高速傳愛~三小時進化 PWA
chph
0
310
Modern Web 2016 議程分享: 網站自動化測試 - 以 PIXNET 搜尋 & 美妝口碑大賞為例
chph
0
140
Other Decks in Technology
See All in Technology
ペアプロの価値はコードを書くことだけじゃない
codmoninc
PRO
0
160
リージョンの壁を越える、 ちょっと変わったAWSサービスの話
falken
PRO
1
300
作り直せるコードは迅速に 作り直せないDBは慎重に - AI時代のプロダクトエンジニアが「判断の不可逆性」で開発速度を変える話
kinosuke01
0
300
#jawssonic2026 あの時代が悪かった ~動かなかったSageMakerと共に迎えたイベント当日~
ktkn1129
0
140
2026-09-11 【Snowflake World Tour Tokyo 2026】Snowflakeを起点に、AI Agentが自律稼働し続ける未来へ / Driving AI Agents with Snowflake
civitaspo
0
290
OpenTelemetry eBPF Instrumentationの舞台裏 / Behind the Scenes of OpenTelemetry eBPF Instrumentation
ymotongpoo
3
970
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
3
450
module Synths; end
asonas
1
130
全員がプロダクトへ向き合う組織を持続成長させるために——組織づくりのフライホイールと4象限 / The Flywheel Model and Four Quadrants for Organizational Design
hiro_torii
4
960
The Agent Builder Loop from Daily Work to OSS
minorun365
PRO
3
120
2026-09-10 【Snowflake World Tour Tokyo 2026】dbt Core と Snowflake で実現する多層的なデータガバナンス / Multi-Layered Data Governance Powered by dbt Core and Snowflake
civitaspo
0
310
あるけみー式LTスライド作成術
alchemy1115
1
160
Featured
See All Featured
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
320
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
970
Utilizing Notion as your number one productivity tool
mfonobong
4
580
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
The Invisible Side of Design
smashingmag
301
52k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
30 Presentation Tips
portentint
PRO
1
390
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Transcript
afu @ 研發中⼼前端組 @afutseng Optimize JavaScript execution and parse time
using optimize-js styleMe 會議室∘2016.09.30
optimize-js https://github.com/nolanlawson/optimize-js Optimize a JavaScript file for faster initial load
by wrapping eagerly-invoked functions 2016/9/18 建⽴的專案 2016/9/20 釋出 v1.0.1 最新版 作者:Nolan Lawson Web Platform PM @ Microsoft Edge
⽤法: optimize-js input.js > output.js 範例輸出 !(function (){})()
function runIt(fun){ fun() } runIt((function (){})) 範例輸⼊ !function (){}() function runIt(fun){ fun() } runIt(function (){})
Benchmark overview 效能評⽐
四⼤名瀏平均速度提昇 3FGFSFODFIUUQTHJUIVCDPNOPMBOMBXTPOPQUJNJ[FKTCFODINBSLPWFSWJFX
jQuery v3.1.0 Minified v.s. Min+Optimized
3FGFSFODFIUUQTHJUIVCDPNOPMBOMBXTPOPQUJNJ[FKTCFODINBSLPWFSWJFX NT NT NT NT NT NT NT NT
⾃⼰做 React 的 benchmark v15.3.2
無痛安裝 React •使⽤ Facebook 出品的 Create React App •https://github.com/facebookincubator/create-react-app $
npm install -g create-react-app $ create-react-app afu-react-test-app $ cd afu-react-test-app/ $ npm start
無痛安裝 React (續) •開發版本本地端網址 • http://localhost:3000/ ! •打包發佈版本 $ npm
run build ! 47.18 KB build/static/js/main.c9763294.js 289 B build/static/css/main.9a0fe4f1.css
以 PHP 7 內建 web server 佈署網站 $ php
-S localhost:8888 PHP 7.1.0-dev Development Server started at Fri Sep 30 01:41:41 2016 Listening on http://localhost:8888 Document root is /Users/citeair/lab/afu-react-test-app/build Press Ctrl-C to quit. [Fri Sep 30 01:41:48 2016] ::1:58054 [200]: / [Fri Sep 30 01:41:48 2016] ::1:58055 [200]: /static/css/main.9a0fe4f1.css [Fri Sep 30 01:41:48 2016] ::1:58056 [200]: /static/js/main.c9763294.js
以 PHP 7 內建 web server 佈署網站
以 Chrome 55 (Canary) 瀏覽
模擬五倍慢低端裝置做 Profiling
Speed improvement ~25% x NT NT
原理? •多數 JavaScript engine 會做 lazy parsing optimization •根據經驗法則,⼤部分的 function
永遠不會或是稍後才被執⾏ •可能不適⽤於 framework-based application,因為打包過的 code 都是 必定會執⾏的 /* 直到 f 被呼叫時才剖析 function 內容 */ function f () { … } •若外部 scope 有⽤變數參照 f,f 會被解析兩次 •優化版,不做 lazy parsing (function f () {...})()
demo by @bmaurer function immutable () { (function (global, factory)
{ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.Immutable = factory()); }(this, function () { ... }); } 71BSTF-B[Z NT 71BSTF-B[Z NT IUUQTHJUIVCDPNSPMMVQSPMMVQQVMMJTTVFDPNNFOU
demo by @bmaurer function immutableOptimize () { (function (global, factory)
{ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.Immutable = factory()); }(this, (function () { ... })); } 71BSTF-B[Z NT IUUQTHJUIVCDPNSPMMVQSPMMVQQVMMJTTVFDPNNFOU
有得必有失 •jQuery v3.1.0:30450 -> 30524 bytes,增加 74 bytes •Lodash v4.15.0:
24528 -> 24577 bytes,增加 49 bytes •React v15.3.2 + Create React App:160518 -> 160609 bytes,增加 91 bytes
Lodash 作者表⽰: •9/20 發布 v4.16.1,改良解析時間兩倍 IUUQTHJUIVCDPNMPEBTIMPEBTIDPNNJUDCDD
Lodash 作者表⽰: IUUQTHJUIVCDPNMPEBTIMPEBTIDPNNJUDCDD
⼩結 • 在 V8 引擎有進⼀步優化以前,很適合在 uglify 後再串接 optimize-js 打包,輕易地換取
JavaScript 解析/執⾏時間縮短
References 1. https://github.com/nolanlawson/optimize-js 2. https://github.com/mishoo/UglifyJS2/issues/886 3. https://github.com/rollup/rollup/pull/774 4. https://github.com/lodash/lodash/wiki/
Changelog#v4161 5. https://github.com/lodash/lodash/commit/ 5c912bcc62d385084cf7f9a13b5ac850a7e72be0
感謝聆聽 @afutseng