Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

网站加载Waiting (TTFB) 优化 #104

Open
bojue opened this issue Dec 8, 2020 · 0 comments
Open

网站加载Waiting (TTFB) 优化 #104

bojue opened this issue Dec 8, 2020 · 0 comments

Comments

@bojue
Copy link
Owner

bojue commented Dec 8, 2020

Waiting (TTFB)

TTFB 是Time To First Byte 的缩写,指的是浏览器开始接受服务器返回数据第一个字节的时间,这里的字节不是响应body的内容,而是http首部的第一个字节,包含了网络路径长度,CDN节点,后台处理,重定向资源,Gzip压缩的处理时间,是判断Web服务端和网络资源响应能力的重要指标,TTFB时间越少证明服务端响应时间越快。

TTFB也是增加谷歌SEO优化的一个指标。

image

TTFB 时间过长的原因

  • 服务端动态模板加载

动态网页资源的返回,需要在服务端计算和加载所需要的数据,首先需要从数据库或者静态文件获取数据,计算之后添加到动态模板,生成压面并渲染,最后返回用户。数据的读取/计算/渲染都需要时间消耗,导致TTFB时间变长。

  • 复杂的防火墙

网络通信通过防火墙的过滤机制,导致TTFB增加。

  • 服务端Gzip压缩处理

Gzip可以压缩资源的大小,优化网路资源请求,但是导致服务端需要在请求的时候压缩资源,增加TTFFB。

  • 网站页面过多的Cookie

每次请求Cookie都要携带到服务端,服务端处理这些Cookie,服务器处理时间增加导致TTFB过长

优化

  • 优化Cookie大小

减少不必要的Cookie字段,有利于优化Cookie的大小

  • 资源缓存

使用CND,对用于来讲资源就近加载

  • 减少动态模板的计算过程

动态模板尽量提前完成计算,缓存在内存,比如支付宝账单功能的生成

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant