Please keep in mind that I have never used web workers before and I had trouble wrapping around them.
Here is an explanation of a simplified version of what I'm doing.
There are links to various files on my page - some are text, some are images, etc. Each file has an image with a common file icon.
I want the script to replace each common icon with a preview of the contents of the file.
the script will request a file from the server (thereby adding it to the cache as a preloader), then create a canvas and draw a preview on it (a thumbnail for images, text exposure for text files, a more specific icon for media files ...) and finally replace the generic icon source with the canvas using the data url.
I can do this quite easily. However, I would prefer to have it in the background so that it does not interfere with the interface when working.
Before diving into this, I need to know: can workers work with canvas, and if so, how would I create it? I donโt think document.createElement('canvas') will work because Workers cannot access the DOM, or I donโt understand when all the links found say that they "cannot access the DOM"?
source share