Jump to content
Larry Ullman's Book Forums

How Much Data Can (And Should) An Ajax Response Handle?


Recommended Posts

Perhaps my brain is just into the whole "use JSON for everything and don't even worry about DB normalization for the sake of speed" these days, but I have a recent project that I'm using Ajax for and the following has me thinking:

 

There are about 40 pages of content total. As it stands, the HTML for each page is stored in a separate row in a DB, and whenever a new page is loaded, Ajax is used to query the DB, return the data and display it. I got to thinking though, what if I just combined all the data for all 40 pages into one row, used some sort of delimiter between page content, and then "JSONed" (that's a word, right? And it doesn't mean to go all "Camp Crystal psycho killer" on someone.) all the data into one JS object?

 

I was thinking that if I put all the data together, on the initial page load, I could take all the data from the DB, sort it into a JS object, and then have everything available for the site locally, and the DB would never have to be queried again. I don't know how many characters there are total, but I'd estimate that the data is about 250-300 kilobytes worth.

 

Anyway, what're everyone's thoughts on this? Thank you.

Link to comment
Share on other sites

I think it's a bad idea. Worth considering, yes, but definitely one to be tossed out. What you're proposing means that the site will virtually serve 40 pages of content whether the user visits one page or 40. That's bad. It's bad for the server and it's bad for the user. For starters, it'll take that much longer for the user to load the initial page. Then, the memory requirement will be exponentially larger than it should be. This is just a bad idea (in case I wasn't clear as to my thoughts on this). To me this strikes as one of those cases of "just because you can do X doesn't mean you should do X".

 

By comparison, if you had a site with a series of pages that are read sequentially, there would be an argument for pre-loading the next page in the series. That's a valid example of loading content that the user might never see, but I'm talking about loading one more page, not 39 more.

Link to comment
Share on other sites

Fair enough. Thanks for your input.

 

To clarify, I was planning on loading the initial page, and once that's displayed, start loading all the others into a JS object. Nevertheless, your points are valid (and are as I suspected), so thank you very much for your input, Larry.

Link to comment
Share on other sites

 Share

×
×
  • Create New...