I have a site that get content from other sites with some JSON and XML API. To prevent loading problems and problems with limitations I do the following:
- PHP - Show the cached content with PHP, if any.
- PHP - If never cached content, show an empty error page and return 404. (The second time the page loads it will be fine "success 200")
- Ajax - If a date field does not exist in the database, or current date is earlier than the stored date, load/add content from API. Add a future date to the database. (This makes the page load fast and the Ajax caches the content AFTER the page is loaded).
I use Ajax just to run the PHP-file. I get the content with PHP.
Questions
- Because I cache the content AFTER it was loaded the user will see the old content. Which is the best way to show the NEW content to the user. I'm thinking automatically with Javascript reload the page or message-nag. Other prefered ways?
- If I use very many API:s the Ajax loadtime will be long and it's a bigger risk that some error will accur. Is there a clever way of splitting the load?
The second question is the important one.