故意减慢 HTML/PHP 页面加载速度进行测试
我很好奇是否存在一种方法可以故意减慢页面加载速度?
我正在测试我的 HTML 和PHP 页面现在在我的本地主机上,我想看看当页面加载速度较慢时我的加载 gif 等将如何执行。
我意识到这是一个罕见的请求,因为大多数开发人员只关心加快页面加载速度,但我认为可能有一种方法,使用 javascript/jQuery 或 PHP 来执行类似的测试目的。
感谢您的帮助!
注意:我正在 MAMP 上进行测试,因此这是在 Mac OS 10.7 上运行的 Apache 服务器
I'm curious if there exists a method to intentionally slow the page load?
I'm testing my HTML & PHP pages on my local host right now, and I want to see how my loading gif etc will perform when the page load is slower.
I realize this is a rare request as most developers are only concerned with speeding up page loads, but I thought there might be a method, using either javascript/jQuery or PHP, to do something like this for testing purposes.
Thanks for any help!
Note: I'm testing on MAMP, so that's Apache server running on Mac OS 10.7
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可以使用php的
sleep($seconds)
函数减慢页面加载速度。但是,您需要将 隐式输出缓冲区刷新设置为“on” 和ob_implicit_flush(true);
如果您希望在页面处理完成之前将任何内容发送到用户的浏览器。否则,您的页面在加载完成之前不会有任何内容。仅仅调用 sleep 并不能解决问题。You can use php's
sleep($seconds)
function to slow down a page load. However, you would need to turn implicit output buffer flushing to "on" withob_implicit_flush(true);
if you want anything to be sent to the user's browser before the page is done being processed. Otherwise your page won't have ANY contents until it's done loading. Calling sleep alone won't do the trick.在 Chrome 中,您可以使用开发人员工具模拟慢速互联网连接。在最右侧的“网络”选项卡下。您可以使用“Fast G3”等预设,也可以使用精确的上传、下载和 ping 数字创建自己的预设。
参考:https://helpdeskgeek.com/networking/simulate-slow-internet-connection-testing/
In Chrome, you can simulate a slow Internet connection with the developer tools. under the "Network" Tab on the far right. You can use a preset like "Fast G3" or can create your own with exact numbers for upload, download and ping.
Reference: https://helpdeskgeek.com/networking/simulate-slow-internet-connection-testing/
穆萨有正确的想法。测试缓慢页面加载的最佳方法是使用 Chrome 的开发人员工具。选择网络选项卡,然后单击显示“无限制”的下拉列表。然后将页面更改为您想要的速度。
这种方式优于使用 sleep 函数,因为您不必弄乱任何代码然后记得将其取出。如果您想更改速度,只需更改节流级别即可。
有关限制的更多信息查看文档。
Moussa has the right idea. The best way to test a slow page load is to use Chrome's developer tools. Select the network tab, and then click the dropdown that says "No throttling". Then change the page to your desired speed.
This way is superior to using the sleep function because you don't have to mess with any code and then remember to take it out. If you want to change the speed, just change the throttling level and you're set.
For more information on throttling check out the docs.
这就是我要尝试的:
使用 php 资源作为图像源:
在 gifLoader.php 中,读取图像文件,在循环中延迟逐字节输出。
在输出二进制数据之前,不要忘记适当设置标头。
参考文献:
更新2015-04-09
使用 Chrome“设备模式”:
该工具具有网络限制功能,可让您查看页面在网络带宽较慢的设备上的呈现方式。它具有许多其他功能,允许您模拟各种设备上的功能,例如屏幕尺寸和触摸。
https://developer.chrome.com/devtools/docs/device-mode
This is what I would try:
Use a php resource as source of the image:
in gifLoader.php, read your image file, output it byte by byte with a delay in the loop.
Don't forget to appropriately set the headers before outputting the binary data.
Referrences:
UPDATE 2015-04-09
Use Chrome 'Device Mode':
This tool has a network throttling feature that allows you to see how your page may render on a device with a slow network bandwidth. It has many other features that allow you to emulate features on various devices such as screen size and touch.
https://developer.chrome.com/devtools/docs/device-mode
一点点 JS setTimeout 就可以解决这个问题
A little bit of JS setTimeout can do the trick
您可以使用 sleep():
You can use sleep():
在 PHP 代码中调用
sleep()
来延迟向服务器发出请求。Call
sleep()
in your PHP code to delay the request to the server.您可以使用 sloppy 本地网络代理 来减慢您的连接速度(它是 JAVA 语言,所以它会可能在您的开发机器上运行,如果您希望浏览器如何响应缓慢的 HTML 加载(例如,动态大小的 HTML 表格等),您可能还需要关闭 mod_deflate 来进行测试。
另外,请参阅 此问题位于 webmasters.stackexchange.com 上
you can use sloppy local web proxy to slow down your connection (it's in JAVA, so it'll probably run on your devel machine. You might also want to turn off mod_deflate for testing purposes, if you want so how your browser responds to slow HTML load (for example, dynamicly sized HTML tables, etc)
Also, see this question on webmasters.stackexchange.com