SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript objects as storage banks...

    Hello,

    I'm relatively new to Javascript, and I have a question related to AJAX and storage of data in Javascript.

    I'm building a video browser for a library of 1500+ videos. The browser has several tabs that offer different ways to view specific types of video. In each tab you can view 20 videos at a time with pagination to the next/prev 20, etc... There is also sorting options. On one tab there are category options, and the videos pulled based on these categories can also be sorted and paginated.

    I am pulling in the data for the list of videos using an XHR that returns data in JSON.

    The way i've programmed it, the data will get pulled from the server and stored into a multidimensional literal array. The intention is to load data from the server only once, store it, and have javascript access it when the user needs it again.

    Well, I'm realizing that as I account for the possible combinations of data (based on tab, category, sort, and page variations) being stored, this storage array is going to get really fat if the viewer does a lot of browsing. Because I'm using a literal array I can avoid looping through it, but I'm still wondering if I'm wasting a lot of resources doing it this way.

    My hope was to avoid having to make redundant requests for data that has already be retrieved, but I'm not sure which is a better solution.

    What do you think?

    Thank you in advance for your response.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    It should be possible for the server itself to cache data for requests that have already occured.
    Last edited by paul_wilkins; Feb 9, 2008 at 16:35.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Enthusiast Boxer's Avatar
    Join Date
    Jan 2008
    Location
    Denver, Colorado
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like you'll need to crate one large array in JS, on the page, and store your 1500 videos there. Of course, I mean only their parameters. Then, based on what tab/category/sorting is selected, you could extract only needed videos from the array into a smaller array (a 2show array , quickly sort it, and then draw the page by copying (with cloneNode()) some template 20 times and using the 2show array's data to fill them.
    Writing a selector/sorter can be difficult, but once you do, you'll be able to quickly construct any page

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I don't see why you can't make many requests, pulling a number of records (say, 100) at a time instead of the whole lot in one request, which can end up being lots of Kb and taking a while to parse into proper javascript.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •