xml - How to cache a jquery Ajax request and parsing -


I am creating an image which is the image gallery, but with many images (archives of documents To browse);

  • Display the "last" and "next" link on the left and right sides of the first image:
  • < P> The previous and next links are obtained from an XML file that lists all the images in the sequence; About 1000-2000 images (one XML file per set) in each set are to avoid viewing the predecessors and the following of future elements, I have included the names of each previous and next images as the property of each image.

    Then the XML file is basically:

      & lt; List & gt; ... & lt; Image back = "ww.jpg" next = "yy.jpg" & gt; Xx.jpg & lt; / Image & gt; & Lt; Image back = "xx.jpg" next = "zz.jpg" & gt; Yy.jpg & lt; / Image & gt; & Lt; Image back = "yy.jpg" next = "aa.jpg" & gt; Zz.jpg & lt; / Image & gt; ... & lt; / List & gt;  

    What I am doing is:

      function display (IMG) {var lookingfor = 'image: contains (' + img + ') '; $ .AJX ({type: "GET", url: "pns.xml", datatype: "xml", success: function (xml) {$ (xml). Find (search) .each (function () {// Display the actual image and link with @previous and @next attributes}}}}}); } $ (Document) .ready (function () {var image = $ .query.get ('img'); display (image);});  

    First page load, script:

    1. The name of the image is displayed to display the URL parameter 'IMG'
    2. the name of all the files Loads the XML file
    3. This receives the previous and next image name from the same file
    4. Displays the image
    5. Displays the previous link And for the next images

    So far, my problem is with other images.

    The link to the previous or next image is:

      display ('image_id');  

    I was hoping that without reloading the page and then calling the 'display' function again I will not have to get the XML file again, and it will not be re-parsed not have to. However, this is not the case: XML file is reloaded with every new call of the 'display' function.

    A significant delay is acceptable when the page loads for the first time; But the same delay for each image seems dull and very unpleasant.

    I have full control over the application; If there is a more efficient solution than XML file to keep the parameters that will be fine. Although the application has to work offline, I can not ask a server to get the names of the preceding / under images.

    In addition, this includes: () The selector is probably not the fastest way: What's better?

    Edit : Using XML and externally loading it was clearly far from optimal; There is a very good and simple approach that each image should have a large object containing an array and load this object once (when the script is first loaded). Another way would be to use some local storage / SQL facility; I can do this with Google Gears which provides such tools. Perhaps Ajax image XML is the global JS first variable and then just query the JS variable on subsequent calls.

      & lt; Script type = "text / javascript" & gt; Var imgXML = null; // document ready $ (function ($ {.ajax ({type: "GET", url: "pns.xml", datatype: "xml", success: function (xml) {imgXml = xml; var image = $ .query.get ('img'); Display (image);}};} The display coming in // Memory Function Display (IMG) goes directly to XML data (if (imgxm! = Null) {var seeing = image : ('+ Img +') '; $ (imgXML). Find (search) .each (function () {// display image and link}}}   

    I'm sure there is another optimization that can be made Ksmel problem must reload.


    Comments

    Popular posts from this blog

    c# - How to capture HTTP packet with SharpPcap -

    php - Multiple Select with Explode: only returns the word "Array" -

    php - jQuery AJAX Post not working -