dscuu86620 2012-05-09 12:55
浏览 43
已采纳

如何在网页上加载大量php生成的图像

I have a website where all the pages have lots of images inside them. Each image is generated dynamically by PHP (I mean that the src="" attribute of the img tag is something like "/image.php?id=4553").

I am controlling the cache properly to speed up the loading of the same image more times and the time it takes to load a single image is very quick. The problem is that the first 5-6 images are loaded in the same time the page loads, the others are loaded MANY SECONDS later (5-10-15 seconds later). Firebug tells me that the problem is due to the queueing of the requests the browsers perform in order to limit simultaneous connections to the server.

I tried sending a "Connection: Keep-Alive" header when I send the HTML of the page, but maybe it's not enough!

Any help?

I know there are jQuery plugins such as lazy load that load images only when they're visible on the viewport. That would be a nice "workaround", but I'd like to know if there's any PROPER way of controlling this type of image loading.

Thank you very much.

  • 写回答

1条回答 默认 最新

  • duanbushi1479 2012-05-09 13:05
    关注

    Firebug is summarizing the problem very well. Browsers will only load x amount of resources from a domain at one time. x is typically around 8 although this can vary by browser and can be changed by users in their settings. The only way to overcome this is to have the browser download resources from different domains (subdomains count as different domains) which will allow for a greater amount of resources to be downloaded at one time. You can probably accomlish this by tricking the browser into thinking it is downloading from different domains by using .htaccess and mod_rewrite to have your images downloaded from fake subdomains which in reality are being downloaded from the same domain. This would allow you to download more then the allotted resources at one time.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题