如何减少“第一个字节的时间”在我的网站上 [英] How to reduce the "Time for the first byte" on my website?
问题描述
网站:
鉴于这种情况,以下代码将给出TTFB(网络延迟+)2s:
<?php ob_start(); ?>
<!doctype html>
< html>
< head>
< title>缓慢加载,缓慢完成< / title>
< / head>
< body>
<?php
sleep(2); // Simulate slow processing
echoBody
?>
< / body>
< / html>
而这会给你一个TTFB(网络延迟+)0s:
<!doctype html>
< html>
< head>
< title>快速加载,缓慢完成< / title>
< / head>
< body>
<?php ob_start(); ?>
<?php
sleep(2); // Simulate slow processing
echoBody
?>
< / body>
< / html>
加载整个页面的时间在两种情况下都是一样的 - 只有延迟发生变化。如果你专注于减少TTFB(为什么),那应该给你足够的信息进一步调查。
重要:有很多前端变更,您应该专注于TTFB。
Website: Stasera in TV
if you go to the homepage, you'll see that before the page loads, the browser waits ...
How i could reduce Time for the first byte?
Nobody can give you a detailed answer without you showing the code responsible for generating the content of the site - because that's where the delay is.
However, since the site is using php, you are most likely using output buffering
Given that's the case, the following code will give a TTFB of (network latency +) 2s:
<?php ob_start(); ?>
<!doctype html>
<html>
<head>
<title>Slow to Load, Slow to finish</title>
</head>
<body>
<?php
sleep(2); // Simulate slow processing
echo "Body"
?>
</body>
</html>
Whereas this will give you a TTFB of (network latency +) 0s:
<!doctype html>
<html>
<head>
<title>Fast to load, Slow to finish</title>
</head>
<body>
<?php ob_start(); ?>
<?php
sleep(2); // Simulate slow processing
echo "Body"
?>
</body>
</html>
The time to load the whole page is the same in both cases - only where the delay is changes. If you are specifically focussed on reducing TTFB (why), that should give you enough information to investigate further.
IMPORTANT: There are a lot of frontend changes you should make before focussing on TTFB.
这篇关于如何减少“第一个字节的时间”在我的网站上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!