I have a web app that's currently ~700 LOC in JS (more is serverside). I'm using jQuery. As I find myself trying to minimize AJAX requests to the server, I've got an awkward mix of caching and spaghetti code developing. It feels like I need a more centralized solution.
My idea: Create a map with the AJAX call to make (URL and args), and a dirty bit. If part of the app decides that the data in the map is outdated, it sets the dirty bit to true
. If a part of the app requests the data, and the data is dirty or doesn't exist, the map will request it from the server before returning it. Otherwise, the map will return it directly.
Does that sound like a good design? Or is there a jQuery plugin or some other code that already does this?