Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

Synchronous and Asynchronous Script Execution

Zarget JS script can be loaded and executed in two ways:

Synchronous code: Scripts are loaded and executed sequentially along with the other web page components. Each time a function is called, the program execution waits until the function is returned before executing the next line of code.

Asynchronous code: Scripts are loaded and executed parallely in one go, wherein scripts are loaded concurrent as other web page components. Asynchronous scripts do not wait for other functions or statements to be executed.

Functionality of Synchronous and Asynchronous Scripts

Whenever a web page gets loaded, the browser looks for directions within the site’s code to render it. This information is almost always provided by the JavaScript tags. The tags have control over the content to be displayed to a visitor and the website’s loading speed.

Loading of webpage mainly constitutes,

loading of visually perceived elements in webpage. It involves all textual, non-textual, graphical and interactive information of the webpage.

  • loading of internal or hidden information used to render the web page. It involves external scripts, stylesheets and metadata information used in the webpage.
  • The loading of this external scripts can be of two types, namely synchronous and asynchronous script loading.

Synchronous Script

In a standard web application, all the request between a client and server are by default synchronous. (ie) A request from a client is sent back with the response before processing further requests of the client.

In the same way, consider the following code snippet:

Synchronous Script

Synchronous Script

Synchronous loading of the script

In synchronous loading of the above script, SecondScript.js is loaded only when the loading of FirstScript.js is complete. Similarly, all requests are handled synchronously.

Synchronous loading of the script

Synchronous loading of the script

The main drawback of the synchronous script is that, when loading of a particular script fails, the rendering of the webpage stops at that particular point.

Asynchronous Script

Asynchronous script involves loading of the external scripts asynchronously, (ie) along side other web elements in the webpage. It is used for rapid rendering of the webpage.

Asynchronous scripts does not force the user to wait till the script load gets complete and in turn allows the user to communicate with web page as the script gets downloaded in the background.

Asynchronous Script

Asynchronous Script

Asynchronous loading of the script

In asynchronous loading of the above script, ThirdScript.js gets loaded concurrently, alongside other scripts getting loaded synchronously.

Any failure in the loading of the script at any point, does not stop the rendering of the webpage in any way.

Asynchronous loading of the script

Asynchronous loading of the script

Zarget Suggests

Asynchronous scripts can compromise your visitor experience and can cause latency during page load. The webpages flicker or blink shortly to switch from the original page to the variation page, when the script gets loaded after the rendering of the webpage. This is commonly called as Flash Of Original Content (FOOC) or page flickering.

Zarget suggests using Synchronous scripts

Let alone of the drawbacks, synchronous scripts provide very high accuracy analytics. It also provides seamless page load without any flickering to the variation page of the experiments being run.

Zarget uses CDN network to transfer the scripts to the client. CDN improves the geographical reachability of the scripts and reduces the round trip in delivering the script.

However, the right fit for your website resides solely on content being served and the existing method used in the webpage.


Technical Support
Don't see what you're looking for? Just drop us a mail

Synchronous and Asynchronous Script Execution