如何使用 python 或 javascript 查找网站的加载时间
How to find load time of the website using python or javascript
我需要找到我当前正在构建的网站的加载时间。我在本地托管了该站点。如何使用 python 或 javascript 找到它的加载时间?我尝试了以下代码,但我认为它是为了响应时间。
from time import time
from urllib.request import urlopen
stream = urlopen('https://01c92730.ngrok.io/index.html')
cream = urlopen('https://01c92730.ngrok.io/Webpage.html')
start_time = time()
output = stream.read()
end_time = time()
stream.close()
print(round(end_time-start_time, 3))
start = time()
output = cream.read()
end = time()
cream.close()
print(round(end-start, 3))`
只需将 var start = Date.now() 放在页面的开头,将 (Date.now() - start) 放在页面的末尾即可加载时间.
案例 1# 不加载库
<doctype html>
<html>
<head>
<script type="text/javascript">
var start = Date.now();
</script>
</head>
<body>
<script type="text/javascript">
document.write("Page load time " + (Date.now() - start) + " milliseconds");
</script>
</body>
</html>
输出:页面加载时间 0 毫秒(有时为 1 毫秒)
案例 2# 加载 jquery 库
<doctype html>
<html>
<head>
<script type="text/javascript">
var start = Date.now();
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
document.write("Page load time " + (Date.now() - start) + " milliseconds");
</script>
</body>
</html>
输出:页面加载时间 24 毫秒(有时是 22,23)
我需要找到我当前正在构建的网站的加载时间。我在本地托管了该站点。如何使用 python 或 javascript 找到它的加载时间?我尝试了以下代码,但我认为它是为了响应时间。
from time import time
from urllib.request import urlopen
stream = urlopen('https://01c92730.ngrok.io/index.html')
cream = urlopen('https://01c92730.ngrok.io/Webpage.html')
start_time = time()
output = stream.read()
end_time = time()
stream.close()
print(round(end_time-start_time, 3))
start = time()
output = cream.read()
end = time()
cream.close()
print(round(end-start, 3))`
只需将 var start = Date.now() 放在页面的开头,将 (Date.now() - start) 放在页面的末尾即可加载时间.
案例 1# 不加载库
<doctype html>
<html>
<head>
<script type="text/javascript">
var start = Date.now();
</script>
</head>
<body>
<script type="text/javascript">
document.write("Page load time " + (Date.now() - start) + " milliseconds");
</script>
</body>
</html>
输出:页面加载时间 0 毫秒(有时为 1 毫秒)
案例 2# 加载 jquery 库
<doctype html>
<html>
<head>
<script type="text/javascript">
var start = Date.now();
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
document.write("Page load time " + (Date.now() - start) + " milliseconds");
</script>
</body>
</html>
输出:页面加载时间 24 毫秒(有时是 22,23)