douyuan4697 2013-08-07 09:57
浏览 52
已采纳

如何使用缓存来加快加载时间? (使用GET方法)

I have a web page that downloads a large amount of preliminary files before showing useful content to users. Sometimes, this can take between 5 and 10 seconds on a standard connection and this can be very frustrating for users to wait for. It's this one file that's taking 90% of the time to load, so I want to do something about it.

I've done some reading about caching... is it possible to have this file's data cached so that it can be loaded instantly next time?

The URL it's obtaining information from looks like this: getData.php?id=A5324DFJK4

This data is being obtained through an AJAX call that returns XML data (then parsed by the app). The reason I used GET is to have it so that particular ID can be cached (I hope I'm right in doing this, the content varies dependent on the ID so I thought caching each one would make sense).

The actual platform the code to cache it would be executed on is a mobile phone, I'm using PhoneGap to build the app when finished. If anyone could enlighten me as to how I could use caching to improve my situation I'd really appreciate it.

Thanks!

  • 写回答

2条回答 默认 最新

  • dongshi9719 2013-08-07 10:13
    关注

    You are right that the browser will cache pages for each individual ID. It's up to you to tell the browser how long you wish to cache this data for. As you've said it's XML, it can be included in the headers for XML you print right now in your getData.php script.

    E.g.:

    header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('+2 days')) . ' GMT');
    header("Content-type: text/xml");
    header("Pragma: cache");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统