Implement the Tealeaf Web Worker script
Improve performance by implementing the optional Tealeaf Web Worker script.
Prerequisites
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 Web SDK queue configuration is conditional on the availability of the fetch API.
Introduction
Modern browsers allow the creation of background tasks within the context of a web application. This technology is referred to as web workers. With Web SDK 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:
- Copy the Tealeaf Web Worker script from the Web SDKrelease bundle into your working directory.
The Tealeaf Web Worker script (tltWorker.js) is included in the Web SDK release bundle in the Worker folder. - Open the Tealeaf Web Worker script in a text editor and copy the pako gzip encoder script into the beginning of the file.
- Save the Tealeaf Web Worker script to a web server directory in the same domain that hosts the application.
It is recommended that you add the tltWorker.js script to the same folder and path used for other site-specific JavaScript, but it is not required.
NOTE: The Tealeaf Web Worker script cannot be combined with the Web SDK or any other script. - Verify the Tealeaf Web Worker script is accessible in a browser by using the URL.
- Initialize the deployed Tealeaf Web Worker script.
To initialize the deployed Tealeaf Web Worker script, add the tltWorker property to the Web SDK queue configuration and replace /js/tltWorker.js with the actual URL or path of the Tealeaf Web Worker script as tested in step 4.
Note: As part of our ongoing transformation, Acoustic has updated the branding in our product URLs, including the Tealeaf collector URL. To access and integrate with Tealeaf, make sure that you replace your old collector URL with this new URL, lib-us-2.brilliantcollector.com. For details, see https://acoustic.com/standardized-acoustic-urls/.
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": "//lib-us-2.brilliantcollector.com",
maxEvents: 50,
timerInterval: 300000,
maxSize: 250000,
checkEndpoint: true,
endpointCheckTimeout: 5000
}
]
},
Updated 5 months ago