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

  • Home
  • SEARCH
  • 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 551117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:21:34+00:00 2026-05-13T11:21:34+00:00

I have a small jQuery script that gets information by looking at an ID.

  • 0

I have a small jQuery script that gets information by looking at an ID.

What is the best way to prevent that the same data are requested more than once (e.g. what’s the best practices for caching in jQuery)?

I have tried to use $.post and $.ajax with option “cache” set to true, but the request is being sent more than once.

Is it better to save collected data and use sets to see whether you’ll have to request it or not?

Any ideas and suggestions are welcome!

If it matters, I use ASP.Net MVC on the server-side.

  • 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-13T11:21:35+00:00Added an answer on May 13, 2026 at 11:21 am

    The cache option you saw on the documentation, refers to the browser’s cache.

    You can implement a pattern of self-memorizing functions in many ways, the goal is that the function result for determined argument (id in your case) is only computed once.

    Since you are using an Ajax request, I would suggest you to use a callback argument also, e.g.:

    var getInfo = (function () {
      var cache = {}; // results will be cached in this object
    
      return function (id, callback) {
        if (cache[id] != null) { // if exist on cache
          callback(cache[id]);
          return;
        }
        // doesn't exists on cache, make Ajax request and cache it
        $.post("info.url", { "id": id }, function (data) { 
          cache[id] = data; // store the returned data
          callback(data);
        });
      };
    })();
    

    Example usage:

    getInfo(5, function (data) {
      alert(data);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 284k
  • Answers 284k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer My understanding is the following: your WelcomeActionBean in not in… May 13, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer There are two approaches to this. First, if you need… May 13, 2026 at 4:31 pm
  • Editorial Team
    Editorial Team added an answer Proper disclosure: I am working with Hila so I was… May 13, 2026 at 4:31 pm

Related Questions

I'm using CakePHP for a small web app and on one form page there's
I have a custom jQuery script that works fine in all bowsers but one
I have a jQuery script that selects all IDs with 'Phone' in them. However,
I have a small problem with my jQuery script. <script language=javascript> $(document).ready(function(){ $('.roll-li').click(function(){ if
I'm very new to the world of jQuery and might be asking a fairly

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.