Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6803081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:18:04+00:00 2026-05-26T19:18:04+00:00

I am using jQuery’s $.ajax method to retrieve some JSON from an API. Each

  • 0

I am using jQuery’s $.ajax method to retrieve some JSON from an API.

Each time the page is loaded, a call to the API is made, regardless if the user has has received this data before – which means when a large amount of users are on the page, the API limiting would come into effect.

My thought of how to deal with this would be firstly pushing the data to a database (pushing to a PHP script), and then checking the database to see if anything is cached, before going back to the API to get more up to date information if required.

Is this a viable method? What are the alternatives?

It just seems like jQuery is actually a hurdle, rather than doing it all in PHP to begin with, but as I’m learning the language, would like to use it as much as I can!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:18:05+00:00Added an answer on May 26, 2026 at 7:18 pm

    In order to help distinguish between opinions and recommended techniques, lets first break down your problem to make sure everyone understands your scenario.

    Let’s say we have two servers: ‘Server A’ and ‘Server B’. Call ‘Server A’ our PHP web server and ‘Server B’ our API server. I’m assuming you don’t have control over the API server which is why you are calling it separately and can’t scale the API server in parallel to your demand. Lets say its some third party application like flickr or harvest or something… let’s say this third party API server throttles requests per hour by your developer API key effectively limiting you to 150 requests per hour.

    When one of your pages loads in the end-users browser, the source is coming from ‘Server A’ (our php server) and in the body of that page is some nice jQuery that performs an .ajax() call to ‘Server B’ our API server.

    Now your developer API key only allows 150 requests per hour, while hypothetically you might see 1000 requests inside one hours to your ‘Server A’ PHP server. So how do we handle this discrepancy of loads, given the assumption that we can’t simple scale up the API server (the best choice if possible).

    Here are a few things you can do in this situation:

    • Just continue as normal, and when jQuery.ajax() returns a 503 service
      unavailable error due to throttling (what most third party APIs do) tell your end user politely that
      you are experiencing higher than normal traffic and to try again
      later. This is not a bad idea to implement even if you also add in
      some caching.
    • Assuming that data being retrieved by the API is cache-able, you
      could run a proxy on your PHP server. This is particularly well
      suited when the same ajax request would return the same response
      repeatedly over time. (ex: maybe you are fetching some description
      for an object, the same object request should return the same description response for
      some period of time). This could be a PHP Pass through proxy or a
      lower level proxy like SQUID caching proxy. In the case of a PHP Pass through proxy you would use the “save to DB or filesystem” strategy for caching and could even re-write the expires headers to suite your level of desired cache lifetime.
    • If you have established that the response data is cache-able, you can
      allow the client side to also cache the ajax response using
      cache:true. jQuery.ajax() actually defaults to having cache:true, so you simply need to not set cache to false for it to be caching responses.
    • If your response data is small, you might consider caching it client-side in a
      cookie. But experience says that most users who clear their temporary
      internet files will also clear their cookies. So maybe the built in caching with jQuery.ajax() is just as good?
    • HTML5 local storage for client-side caching is cool, but lacks wide-spread popular support.
      If you control your user-base (such as in a corporate environment) you
      may be able to mandate the use of an HTML5 compliant browser. Otherwise, you
      will likely need a cookie based fallback or polyfill for browsers lacking
      HTML5 local storage. In which case you might just reconsider other options above.

    To summarize, you should be able to present the user with a friendly service unavailable message no matter what caching techniques you employ. In addition to this you may employ either or both server-side and client-side caching of your API response to reduce the impact. Server-side caching saves repeated requests to the same resource while client side caching saves repeated requests to the same resources by the same user and browser. Given the scenario described, I’d avoid Html5 LocalStorage because you’ll need to support fallback/polyfill options which make the built in request caching just as effective in most scenarios.

    As you can see jQuery won’t really change this situation for you much either way vs calling the API server from PHP server-side. The same caching techniques could be applied if you performed the API calls in PHP on the server side vs performing the API calls via jQuery.ajax() on the client side. The same friendly service unavailable message should be implemented one way or another for when you are over capacity.

    If I’ve misunderstood your question please feel free to leave a comment and clarify and/or edit your original question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using JQuery Validation plugin, I am trying to call the .valid() method without the
Using JQuery, I am loading a div from an external HTML page into fancybox
Using jQuery Ajax to fetch data from local server: it works well with IE8
Using jQuery to make an AJAX call to a PHP file results in the
Using jQuery, is there some property on an element that I can set to
Using jquery (javascript) need to display facebook user name in html page using facebook
Using jquery, i fetch a data from php to div $.post(url.php?info=+$('#info').val() // rest of
Using jQuery how would I find/extract the Spartan string if the outputted HTML page
using jquery, how can you distinguish between refreshing vs. navigating away from the current
Using jQuery's delegate() method, can I get the index number of the current element?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.