「译」 如何做到一秒渲染一个移动页面( 五 )


当然可以 。有很多商业的或开源的网页性能优化(WPO)产品都可以帮你达成上述部分或全部准则 。对于开源解决方案,不妨看看%20PageSpeed%20优化工具 。
How%20do%20I%20tune%20my%20server%20to%20meet%20these%20criteria?我怎样调整我的服务器来符合这些准则?First,%20ensure%20that%20your%20server%20is%20running%20an%20up-to-date%20version%20of%20the%20operating%20system.%20In%20order%20to%20benefit%20from%20the%20increased%20initial%20TCP%20congestion%20window%20size%20(IW10),%20you%20will%20need%20linux%20kernel%202.6.39+.%20For%20other%20operating%20systems,%20consult%20the%20documentation.
首先,确保你的服务器正在运行最新版的操作系统 。为了从%20TCP%20初始拥塞窗口数量的增加(IW10)中获益,你需要%202.6.39+%20版本的%20Linux%20内核 。对于其它操作系统,请查阅相关文档 。
To%20optimize%20server%20response%20time,%20instrument%20your%20code,%20or%20use%20an%20application%20monitoring%20solution%20to%20identify%20your%20bottleneck%20-%20e.g.,%20scripting%20runtime,%20database%20calls,%20RPC%20requests,%20rendering,%20etc.%20The%20goal%20is%20to%20render%20the%20HTML%20response%20within%20200%20milliseconds.
为了优化服务器的响应时间,请测评你的代码性能,或使用监控程序来发现性能瓶颈——比如脚本运行时、数据库调用、RPC%20请求、渲染等等 。最终目标就是在%20200%20ms%20内渲染出%20HTML%20响应内容 。
What%20about%20Content%20Security%20Policy?内容安全策略(Content%20Security%20Policy)怎么办?If%20you%20are%20using%20CSP,%20then%20you%20may%20need%20to%20update%20your%20default%20policy.
如果你正在使用%20CSP,那么你可能需要更新你的默认策略 。(译注:CSP%20是一项用于防范%20XSS%20的安全性规范,具体参见%20Content%20Security%20Policy%20-%20维基百科 。)
First,%20inline%20CSS%20attributes%20on%20HTML%20elements(e.g.,%20<p%20style=...>)%20should%20be%20avoided%20where%20possible,%20as%20they%20often%20lead%20to%20unnecessary%20code%20duplication,%20and%20are%20blocked%20by%20default%20with%20CSP%20(disabled%20via%20“unsafe%20inline”%20on%20“style-src”).%20If%20you%20have%20inline%20JavaScript,%20then%20you%20will%20need%20to%20update%20the%20CSP%20policy%20with%20“unsafe-inline”%20to%20enable%20its%20execution.%20By%20default,%20CSP%20will%20block%20all%20inline%20script%20tags.
首先,尽可能避免在%20HTML%20元素中内联%20CSS%20属性(比如这样%20<p%20style=...>),因为它们常常导致不必要的重复代码,而且默认会被%20CSP%20拦截(对%20style-src%20字段使用%20unsafe-inline%20指令可以禁用此类拦截) 。如果你使用了内联的%20JavaScript,那么你需要在%20CSP%20策略中使用%20unsafe-inline%20指令来令其执行 。默认情况下,CSP%20将拦截所有内联脚本标签 。(译注:这里的“内联%20JavaScript”包括多种形态的%20HTML%20内部的脚本代码,包括类似%20<script>foo();</script>%20这样的内嵌脚本标签、<a%20href="javascript:foo();">%20这样的伪协议%20URL、以及%20<a%20href="#"%20onclick="foo();">%20这样的事件处理属性 。)
希望本文能帮助到您!点赞+转发,让更多的人也能看到这篇内容(收藏不点赞,都是耍流氓-_-)
关注%20{我},享受文章首发体验!
每周重点攻克一个前端技术难点 。更多精彩前端内容私信%20我%20回复“教程”
原文链接:https://github.com/cssmagic/blog/issues/20
 




推荐阅读