Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6066303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:29:11+00:00 2026-05-23T09:29:11+00:00

As far as I can tell, web workers need to be written in a

  • 0

As far as I can tell, web workers need to be written in a separate JavaScript file, and called like this:

new Worker('longrunning.js')

I’m using the closure compiler to combine and minify all my JavaScript source code, and I’d rather not have to have my workers in separate files for distribution. Is there some way to do this?

new Worker(function() {
    //Long-running work here
});

Given that first-class functions are so crucial to JavaScript, why does the standard way to do background work have to load a whole other JavaScript file from the web server?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:29:11+00:00Added an answer on May 23, 2026 at 9:29 am

    http://www.html5rocks.com/en/tutorials/workers/basics/#toc-inlineworkers

    What if you want to create your worker script on the fly, or create a self-contained page without having to create separate worker files? With Blob(), you can "inline" your worker in the same HTML file as your main logic by creating a URL handle to the worker code as a string

    Full example of BLOB inline worker:

    <!DOCTYPE html>
    <script id="worker1" type="javascript/worker">
      // This script won't be parsed by JS engines because its type is javascript/worker.
      self.onmessage = function(e) {
        self.postMessage('msg from worker');
      };
      // Rest of your worker code goes here.
    </script>
    <script>
      var blob = new Blob([
        document.querySelector('#worker1').textContent
      ], { type: "text/javascript" })
    
      // Note: window.webkitURL.createObjectURL() in Chrome 10+.
      var worker = new Worker(window.URL.createObjectURL(blob));
      worker.onmessage = function(e) {
        console.log("Received: " + e.data);
      }
      worker.postMessage("hello"); // Start the worker.
    </script>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As far as I can tell, any section in a web.config file can be
As far as I can tell, this is isn't possible, so I'm really just
As far as I can tell, the best way to do this is do
As far as I can tell, this code is fine, and should display some
I have this trigger which works functionally (as far as I can tell by
I have some simple javascript that as far as i can tell should work
As far as I can tell i'm doing everything by the book, but the
As far as I can tell, there is no API (official or unofficial) to
As far as I can tell, Scala has definitions for the Enumeration Value class
As far as I can tell I wouldn't think it would make any difference

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.