jquery - How can I make this javascript more efficient? -
I am getting a piece of plain HTML from AJAX request.
& lt; H1 & gt; Title & lt; / H1> & Lt; Div & gt; Content & lt; / Div & gt;
This is the simplest form for each title in a and lt; H1 & gt;
is tagged, and a containing the content and lt; Div & gt;
tag I have a well-formatted container
in the html page, which needs to be populated with the returned HTML snippet.
This container is:
& lt; Div id = "container" & gt; & Lt; Div class = "header" & gt; & Lt; / Div & gt; & Lt; Div class = "content" & gt; & Lt; / Div & gt; & Lt; / Div & gt; I use the following JavaScript function to parse html
and put it in the container
.
Function Load Communication (ID, Data) {var Container = $ ('#' + ID); Var title = ''; Var content = ''; $ (Data). Filter ('H1: First'). Each (function () {title = $ (this) .html (); content = $ (this) .next () .html ();}); $ ('Div.header', container) .html (title); $ ('Div.content', container) .html (content); }
Everything is working 'allraide', there are subsequent Ajax requests that load various HTML content very quickly. But when I click on a link that calls for a full page refresh, it hangs for about 3 or 4 seconds before clicking the hyperlink, I think this is a javascript problem, maybe where something Does the content remain in memory? Can anyone see why it can be inefficient?
I use a debugger to delay some source of firefox w / firebug Like, to verify that the link refreshes the whole page is actually calling this code and is not hanging anywhere else. And Firefox W / Taperdata to see the requests that are going out and to come back to see if there is a delay due to waiting for an external response.
:(
Comments
Post a Comment