Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hemkaran
Created February 28, 2018 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hemkaran/73cfe4b5dba4c6d793ab4646ae009de1 to your computer and use it in GitHub Desktop.
Save hemkaran/73cfe4b5dba4c6d793ab4646ae009de1 to your computer and use it in GitHub Desktop.
This file demonstrate using web worker to compress the data at frontend side (step 3)
$.ajax({
url: workerUrl,
dataType: 'text',
success: function (data) {
try {
// Create a blob of the file content, so that we can create blob URL out of it, that can
// be passed to create a web worker file (that runs in the background thread)
var blob = new window.Blob([data], {type: 'text/javascript'});
var workerBlobUrl = window.URL.createObjectURL(blob);
// workerBlobUrl now is the URL to worker file, now we need to create a web worker using this URL.
var worker = new Worker(workerBlobUrl);
// Implemented in the next step.
workerInitialized(worker);
} catch (e) {
console.log('Error in initializing worker file');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment