jquery how should i search multiple html files for results in realtime using web workers

Discussion in 'JavaScript' started by sumgeeks, Dec 4, 2013.

  1. #1
    i have this Fiddle Here http://jsfiddle.net/kd6Y4/4/

    which is getting div from a different page on same site and display it the problem is its working perfectly online like this direct link http://fiddle.jshell.net/kd6Y4/1/show/ search for hand or and in both

    but there is a problem if i am searching a html file which is around 7 mb with more than 6000 div its hanging for around 20 seconds before giving results and sometime chrome closes when testing i want to load results from multiple html files at a time and in a way so that results should show instantly and realtime when the searching is being processed and also it should search multiple html files one after other and display results in chronological order please help
    the code i am using is working for average sized file
    i have heard about http://adambom.github.io/parallel.js/ but not getting how to use it please help and if possible then by updating my jsfiddle http://jsfiddle.net/kd6Y4/4/ the present search code is working fast for small files but i need this to work faster for big sizes such as 7 mb html with more than 6000 div as well i will be using it offline in a android app
    same origin policy of javascript is not a issue have already fixed that in app
     
    sumgeeks, Dec 4, 2013 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Why the h*ll do you have a 7MB html-file - that's the first question, with more than 6000 div's - that's the second question. What I would focus on is a redesign of your data, simply because that's just... horrible. A 7MB html file contains more than 7 million characters - and if that's mostly content, it's gonna take a while to process...
     
    PoPSiCLe, Dec 5, 2013 IP
  3. sumgeeks

    sumgeeks Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    Its a ebook written in html each div contains content with id attributes
     
    sumgeeks, Dec 5, 2013 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    This is an excellent example of a time where jquery's overhead is just going to bite you in the ass. (like there's ever a time where it doesn't)... My advice? FORGET ALL THAT CRAP, and instead of looking for DIV (sloppy) walk the DOM looking for textNodes. You could then do a regex on each textNode for what you want. To prevent the browser from killing the script you need to exit execution regularly, so just watch Date().getTime(); and every say.... second exit out of your search function, and do a settimeout(resumeFunction, 0) or some such.

    ... if you want DIV as your result set, just do parentNodes until you hit a DIV. (or BODY as a fallback)

    -- edit -- my bad, I thought you were searching on the currently loaded page, not ajaxing one in. That's different then... but not too different... though it treads into something I'd probably be trying to handle server-side instead of client-side. (especially since you could add result caching, very handy if those pages are static).
     
    deathshadow, Dec 6, 2013 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    Oh, BTW in your sample file, id="Genesis 1:7" is an invalid ID, since ID's cannot contain spaces, or colons. The extra parent DIV for nothing, and WORSE the multiple instances of BODY sure as shine-ola are likely screwing up processing as well, making any script's attempt to go through that VERY difficult.
     
    deathshadow, Dec 6, 2013 IP