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 4613822
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:36:31+00:00 2026-05-22T01:36:31+00:00

I have a page that is using jQuery to load an XML file, which

  • 0

I have a page that is using jQuery to load an XML file, which I’m then outputting the contents of to the page.

Recently I added a sorting function to the output which is causing a 1+ or 2+ minute hang on Safari on an iPod Touch (depending upon how many fields I sort by) and a less than 1 minute hang on an iPad. The same sort returns within a few seconds on Firefox 4.0.1.

I’m afraid it’s just a limitation of the iOS, but before I removed the sort, perhaps there’s an optimization that could be made.

Before the filter there’s 357 items in the XML. After the filter there’s 199 items that are sorted through.

var videoGames = $($.parseXML(videoGameXml)).find("game");
videoGames = videoGames.filter(function (a) {
    return ($(this).attr('addOn') != "true" && $(this).find('own').text() == "yes");
});
videoGames.sort(function (a, b) {
    var firstTitle = $(a).find('title').text().toLowerCase();
    var secondTitle = $(b).find('title').text().toLowerCase();
    var firstSystem = ($(a).find("console").text() + " " + $(a).find("version").text()).toLowerCase();
    var secondSystem = ($(b).find("console").text() + " " + $(b).find("version").text()).toLowerCase();

    if (firstSystem != secondSystem) {
        if (firstSystem > secondSystem) {
            return 1;
        } else {
            return -1;
        }
    } else {
        if (firstTitle > secondTitle) {
            return 1;
        } else if (secondTitle < firstTitle) {
            return -1;
        }
    }
    return 0;
});
videoGames.each(function () {
    // runs quickly, so removed
});

Note that if I remove the system check as an initial ‘optimization’ that cuts the time about in half on the iPod Touch, but still results in the 1+ minute hang mentioned above.

So, is it an iOS device limitation, or can I optimize my sort?

  • 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-22T01:36:32+00:00Added an answer on May 22, 2026 at 1:36 am

    Every time you do $(a) it will perform a very complex set of operations, so you better cache it. Also, you don’t need the Title if System is different. This version should speed it up a bit:

    videoGames.sort(function (a, b) {
        var first = $(a);
        var second = $(b);
        var firstSystem = (first.find("console").text() + " " + first.find("version").text()).toLowerCase();
        var secondSystem = (second.find("console").text() + " " + second.find("version").text()).toLowerCase();
    
        if (firstSystem != secondSystem) {
            if (firstSystem > secondSystem) {
                return 1;
            } else {
                return -1;
            }
        } else {
            var firstTitle = first.find('title').text().toLowerCase();
            var secondTitle = second.find('title').text().toLowerCase();
    
            if (firstTitle > secondTitle) {
                return 1;
            } else if (secondTitle < firstTitle) {
                return -1;
            }
        }
        return 0;
    });
    

    You could also cache the values in the object

    Then, instead of:

    var firstSystem = (first.find("console").text() + " " + first.find("version").text()).toLowerCase();
    

    Do:

    var firstSystem = first.data('system');
    if (!firstSystem) {
        firstSystem = (first.find("console").text() + " " + first.find("version").text()).toLowerCase();
        first.data('system') = firstSystem;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a web page that is using jQuery. I have an
I have an xml file which I imported in my html page like this:
I have a page that is using a non-standard font and arial as a
I have a page that is currently using the datetime microformat to display a
I have a web page that is being displaying in a winform app using
I have a view using a master page that contains some javascript that needs
I have a page that is generated which inserts an HTML comment near the
I have an ASPX page that I am using to write JSON. It works
I have a page with a div that is dynamically filled using a paginator
I have page that has some javascript that needs to run at page load.

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.