doubi5520 2015-04-22 18:22
浏览 33
已采纳

获取数据的角度方式

I have site which is completely driven by ajax. When an user goes to some category page I want to show products there. What's the best way to fetch products for that category? I have 2 options:

  1. save all products into js variable threw php at first load of website, then when the user goes to some category filter this array to get only those products which has this category and send them to view

  2. dont save all produts into variable in the beggining, but fetch them threw api when an user touch some category

I think first option will be better because all products will be loaded in the begginging and then if an user touch 50 categories, I will not have to send 50 requests for products. But I'm not sure(maybe potencial problem if I have big amount of products)

Thanks.

  • 写回答

1条回答 默认 最新

  • duanli9001 2015-04-22 19:01
    关注

    You could also load all of the product data after the angular app has loaded.

    At any rate, it vastly depends on how much product data you have and your current load time. It it's a small amount of products that combined only make up a 100kb json object, it doesn't really matter.

    But if you have more than a trivial amount of data, and/or your average user is only accessing a small percentage of your product data, it makes more sense to load it on demand. You can always keep the data in memory so if the user switches back and forth from cat A -> cat B -> cat A, you only load each cat A & B once.

    In the end, you just need to analyze your load times and how much data your thinking of loading. If loading it all in one go is still acceptably fast you should be fine, it it feels too slow then you need to optimize and load more things on demand as they are needed.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度