【 以下文字转载自 Programming 讨论区 】
发信人: eGust (十年), 信区: Programming
标 题: The cost of JavaScript in 2019
发信站: 水木社区 (Fri Jun 28 19:30:18 2019), 站内
google 每年一次的讲解为什么要减小 js 的体积的文章又来了
https://v8.dev/blog/cost-of-javascript-2019
The cost of JavaScript in 2019
Published 25 June 2019
图文并茂所以就不转了,只转最重要的部分:
Actionable high-level guidance
What does this mean for web developers? Parse & compile costs are no longer as slow as we once thought. The three things to focus on for JavaScript bundles are:
* Improve download time
Keep your JavaScript bundles small, especially for mobile devices. Small bundles improve download speeds, lower memory usage, and reduce CPU costs.
Avoid having just a single large bundle; if a bundle exceeds ~50–100 kB, split it up into separate smaller bundles. (With HTTP/2 multiplexing, multiple request and response messages can be in flight at the same time, reducing the overhead of additional requests.)
On mobile you’ll want to ship much less especially because of network speeds, but also to keep plain memory usage low.
* Improve execution time
Avoid Long Tasks that can keep the main thread busy and can push out how soon pages are interactive. Post-download, script execution time is now a dominant cost.
* Avoid large inline scripts (as they’re still parsed and compiled on the main thread). A good rule of thumb is: if the script is over 1 kB, avoid inlining it (also because 1 kB is when code caching kicks in for external scripts).
另外这次还做了个视频
https://www.youtube.com/watch?v=X9eRLElSW1c--
FROM 125.238.192.*