简体   繁体   中英

How to use caching to speed up load times? (using GET method)

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!

Can you process the data further on the server and cache it there? There really isn't much to go with your problem description.

Example on caching something created with PHP http://www.php.net/manual/en/function.header.php#61903

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.

Eg:

header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('+2 days')) . ' GMT');
header("Content-type: text/xml");
header("Pragma: cache");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM