Kishore
Kishore

Reputation: 1912

caching jquery get requests

I have an application which make multiple get requests to a web service and displays a map using that data. i use this in multiple places. since the map is taking time to load what is the best way to cache the get request?

i am thinking of the following approach

if i just use Memcache to cache the response my application still make a get request. to further optimize i can use the jquery/javascript caching and set the Http cachingheader.

is there any way other way that can be implemented to improve the performance? because i dont want to make multiple get requests across all the pages to display the same map content.

thanks

Upvotes: 0

Views: 209

Answers (1)

SadullahCeran
SadullahCeran

Reputation: 2435

The best approach to your situation is to set Cache and Expires HTTP headers from server side, and force Jquery to use cache while making requests. If applicable, I also recommend sending Modified Date from server so After caching expires, JQuery first asks if content of the service has changed from last-modified-date.

If you successfully apply caching headers, Client side code will not issue a http request until cache time expires.

There are three main caching approaches (AFAIK) to improve performance :

  • Database caching. Caching the query and results at data level so that when a service issues a query, it doesn't execute every time. If your database query takes a lot of time, and different clients issue same service requests, you should think about it.
  • Server memory caching. If applied, the server does not executes the action and returns the content from cached memory. This approach is simpler from data caching mostly, and more beneficial.
  • Client caching via HTTP Headers: This is the most useful and fitting solution to your situation. If a client makes a HTTP Request to same service with same parameters more than one in the lifecycle, than there is no need to fetch the same response from server again and again (like static pages, images, css's and javascript files). You may use Cache-Control header and max-age attribute to achieve this purpose.

Upvotes: 1

Related Questions