Skill Level: Advanced


The Tealeaf Web Worker script relies on the fetch API for network communication. The Tealeaf Web Worker script does not function on browsers that do not support fetch. Thus, the initialization of the Tealeaf Web Worker in the UIC queue configuration is conditional on the availability of the fetch API.


Modern browsers allow the creation of background tasks within the context of a web application. This technology is referred to as web workers. With UIC 5.6.0 (and above), applications can use the optional Tealeaf Web Worker script to offload the JSON serialization, gzip encoding, and network communication tasks. Some processing that would otherwise occur in the main application thread is moved into a parallel worker thread, which results in a performance boost. 
The performance improvement varies depending on the application. In general, applications that have large DOM sizes and make heavy use of the CPU are more likely to experience performance improvements when using the Tealeaf Web Worker script.


Deploy the Tealeaf Web Worker script

To deploy the Tealeaf Web Worker in your application, follow these steps: 


  1. Copy the Tealeaf Web Worker script from the UIC release bundle into your working directory.

    The Tealeaf Web Worker script (tltWorker.js) is included in the UIC release bundle in the Worker folder.

  2. Open the Tealeaf Web Worker script in a text editor and copy the pako gzip encoder script into the beginning of the file.

  3. Save the Tealeaf Web Worker script to the web server directory that hosts application scripts.

    It is recommended that you add the tltWorker.js script to the same folder and path as the UIC, but it is not required. 

    NOTE: The Tealeaf Web Worker script cannot be combined with the UIC or any other script.

  4. Verify the Tealeaf Web Worker script is accessible in a browser by using the URL.

  5. Initialize the deployed Tealeaf Web Worker script.

    To inialize the deployed Tealeaf Web Worker script, add the tltWorker property to the UIC queue configuration and replace /js/tltWorker.js with the actual URL or path of the Tealeaf Web Worker script as tested in step 4.

    queue: {
    	// WARNING: Enabling asynchronous request on unload may result in incomplete or missing data
    	asyncReqOnUnload: false,
    	useBeacon: true,
    	xhrLogging: true,
    	tltWorker: window.fetch && window.Worker ? new Worker("/js/tltWorker.js") : null,
    	queues: [{
    			qid: "DEFAULT",
    			"endpoint": "//collector.tealeaf.ibmcloud.com/collector/collectorPost",
    			maxEvents: 50,
    			timerInterval: 300000,
    			maxSize: 250000,
    			checkEndpoint: true,
    			endpointCheckTimeout: 5000

Expected outcome

The Tealeaf Web Worker is deployed in your application. 

Join The Discussion

Your email address will not be published. Required fields are marked *