dtwbp26022 2011-07-26 08:04
浏览 69

限制/延迟或其他优化以避免jQuery请求的停顿/错误500

I have a page that is updated using jQuery according to a few actions that a user can carry out.

I've noticed that requests can stall or the server simply gives an 500 error. This could be an indication that too many requests are taking place simultaneously.

The following actions can take place:

  • User hits rating button for an image, jQuery updates the new rating.
  • User hits next button, jQuery fetches the description in JSON of a new random image, jQuery updates a few html attributes to show the new image.
  • User activates the scrollbar of an infinite scrolling gallery, jQuery monitors the position of the last image and fetches the description of a new random image each time a limit is reached.
  • User clicks a thumbnail, jQuery updates the attributes to show a full size image.
  • User enters text in a field to post a comment, hits button, jQuery updates the database.
  • User hits favourite button, jQuery updates database with the user's favourites.
  • Adding to this, url rewriting to redirect image requests to an image-resizing script which takes the original image and resizes it according to a maximum height/width and then caches it in a directory.

One of the things that can happen is that a user can press the next button repeatedly or they action the scroller continously. This in turn can cause a lot of requests to "pile up".

What could I do to delay actions (disable buttons? add a minimal interval between requests? ...) and what other forms of optimizations could be used?

  • 写回答

2条回答 默认 最新

  • dsafgdafgdf45345 2011-07-26 08:18
    关注

    First of all, you can fetch not only next image, but lets say 10 images in one request. When the user is repeatedly clicking next, do not fire request on each next. Fire request with setTimeout() of 0.5 seconds, clearing previous timeout. You may log how many times the 'next' was clicked in order to retrieve the correct number of images. For the rating, favourite and comment, the logic is perfectly valid, so you should only ensure that those operations on the server side are as fast as possible.

    User activates the scrollbar of an infinite scrolling gallery, jQuery monitors the position of the last image and fetches the description of a new random image each time a limit is reached.

    Once again, do not fetch them 1 by one, fetch them in groups

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么