Jack James
Jack James

Reputation: 5372

Should I use JQuery instead of PHP for loading external JSON?

I've got a webpage that makes several calls to external site APIs. Right now, I do this via PHP, and cache the responses to disk (using cachelite) where I can. Even so, the page seems to load very slowly, and I'm struggling to find a likely cause (the page speed tab in Chrome is not providing any useful clues).

So I wonder if there might be some benefit to having the client process the API calls via JQuery instead, so that at least the initial page load for the user is faster. Is it worth me doing this, or would I be better off trying to optimise the PHP code further?

Upvotes: 0

Views: 292

Answers (3)

Jack James
Jack James

Reputation: 5372

I've been thinking about the two answers above and think maybe what I could do is combine both approaches, that is to say, have the json fetched and cached by a server-side php script, but have the user-facing PHP files use jquery to load data from the file.

Upvotes: 0

rahul maindargi
rahul maindargi

Reputation: 5635

PHP is server side scipting. If you are not doing anything on server but just loading the contents from external Site APIs I think it would be better if you use jQuery or javascript to the job for you.

Upvotes: 2

Niels
Niels

Reputation: 49929

It depends, if you want to have the result of the JSON indexed by Google, you need to parse it through PHP.

If you want the fastest way and less server load, use Javascript to load the JSON, the JSON will be loaded from an external source and cached by the users browser.

What is the load time of the JSON? Maybe the other server is slow?

Upvotes: 2

Related Questions