Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to run multiple internal javascript codes asynchronously and not block?
    primarykey
    data
    text
    <p>I have a webpage created by a php script that upon loading will contain 0 to N div elements. For each div I run a specific javascript code that manipulates data relevant to that div. One of the things this code does is create an <em>img</em> element and set its '<em>src</em>' attribute to a certain url of an image of a known (but variable) size. This is done for caching. Those images are not supposed to be displayed in the initial page layout - but each should appear after a certain user input (mouse hover) - so I'm trying to cache the images so it won't take long for them to appear.</p> <p>The loading of the images of-course takes time - and each time an image loads the code blocks resulting in high load times. an example:</p> <pre><code>&lt;div id="i1"&gt; &lt;script type="text/javascript"&gt; /* run code relevant to 'i1', and amongst other things load some image into a detached img element for later use. let's call this code 'bcode' */ &lt;/script&gt; &lt;div id="i2"&gt; &lt;script type="text/javascript"&gt; /* run 'bcode' for i2 */ &lt;/script&gt; &lt;div id="...and so on"&gt; </code></pre> <p>To try having the code run asynchronously, I tried this:</p> <pre><code>&lt;div id="i1"&gt; (function() { var asyncScriptElement = document.createElement('script'); asyncScriptElement.async = true; var scriptText = document.createTextNode ('here I put all of the relevant "bcode"'); asyncScriptElement.appendChild (scriptText); document.getElementById ('Img_1_2').appendChild (asyncScriptElement); }()); </code></pre> <p>It works under FF (still not fast enough), and it obviously doesn't work under IE. Do you have any suggestion as to how to achieve this? Also note, that I don't really need to get anything from another external php (i.e. to use XMLHttpRequest) - I got all the data I need in this php. I just need a way to make the loading of the images unblocking...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload