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

  • SEARCH
  • Home
  • 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 9261431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:08:41+00:00 2026-06-18T13:08:41+00:00

Please bear in mind that I have never used Web Workers before and I’m

  • 0

Please bear in mind that I have never used Web Workers before and I’m having some trouble wrapping my head around them.

Here’s an explanation of a simplified version of what I’m doing.

My page has links to various files – some are text, some are images, etc. Each file has an image showing a generic file icon.

I want the script to replace each generic icon with a preview of the file’s contents.

The script will request the file from the server (thereby adding it to the cache, like a preloader), then create a canvas and draw the preview onto it (a thumbnail for images, an excerpt of text for text files, a more specific icon for media files…) and finally replace the generic icon’s source with the canvas using a data URL.

I can do this quite easily. However, I would prefer to have it in the background so that it doesn’t interfere with the UI while it’s working.

Before I dive right in to this, I need to know: can Workers work with a canvas, and if so how would I create one? I don’t think document.createElement('canvas') would work because Workers can’t access the DOM, or am I misunderstanding when all the references I’ve found say they “can’t access the DOM”?

  • 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-06-18T13:08:42+00:00Added an answer on June 18, 2026 at 1:08 pm

    You cannot access the DOM from web workers. You cannot load images. You cannot create canvas elements and draw to them from web workers. For now, web workers are pretty much limited to doing ajax calls and doing compute intensive things. See this related question/answer on web workers and canvas objects: Web Workers and Canvas and this article about using webworkers to speed up image manipulation: http://blogs.msdn.com/b/eternalcoding/archive/2012/09/20/using-web-workers-to-improve-performance-of-image-manipulation.aspx

    Your simplest bet is to chunk your work into small chunks (without web workers) and do a chunk at a time, do a setTimeout(), then process the next chunk of work. This will allow the UI to be responsive while still getting your work done. If there is any CPU consuming computation to be done (like doing image analysis), this can be farmed out to a web worker and the result can be sent via message back to the main thread to be put into the DOM, but if not, then just do your work in smaller chunks to keep the UI alive.

    Parts of the tasks like loading images, fetching data from servers, etc… can also be done asynchronously so it won’t interfere with the responsiveness of the UI anyway if done properly.

    Here’s the general idea of chunking:

    function doMyWork() {
        // state variables
        // initialize state
        var x, y, z;
    
        function doChunk() {
            // do a chunk of work
            // updating state variables to represent how much you've done or what remains
    
            if (more work to do) {
                // schedule the next chunk
                setTimeout(doChunk, 1);
            }
    
        }
        // start the whole process
        doChunk();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller posts: www.mydomain.com/posts/123-hello Please bear in mind that the 123 is
Please bear in mind that I'm totally new to Rails when answering this.My question
Please bear with me as I am new to dojo, javascript, and web programming
I'm new to iPad development so please bear with me. I have an iPad
So I'm working on my first multithreaded WPF app. Please bear in mind I
I'm brand new to OData, so please bear with me. Assuming that I'm using
please bear in mind I am not a GUI programmer . As the title
Bear in mind, I have researched this and have found several articles, however, they
Please keep in mind that I'm rather new to how MVC, Json, jQuery, etc.
Please bear with me if this isn't clear, this is my first posting here.

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.