Service Worker vs Shared Worker

A service worker has additional functionality beyond what’s available in shared workers, and once registered, they persist outside the lifespan of a given web page. Service workers can respond to message events, like shared workers, but they also have access to additional events. Handling fetch events allows service workers to intercept any network traffic (originating … Read more

Sharing websocket across browser tabs?

After seeing this question, I’ve finally implemented sharing socket and added to my library a few days ago. It seems to work in most of browsers including even in IE6, but except Opera. For Opera, you may use regular checking instead of unload event. Check releated issue at https://github.com/flowersinthesand/portal/issues/21 ###Leaving a cookie Set cookie to … Read more

Uncaught ReferenceError: importScripts is not defined

When you create a worker it is actually executed twice. The first pass is in the context of the global ‘window’ object(meaning you have access to all the window object functions). The second call through is in the context of the worker which has a different global object, one where ‘importScripts’ exists. // proper initialization … Read more

Is there a way to create out of DOM elements in Web Worker?

Alright, I did some more research with the information @Bergi provided and found the following discussion on W3C mailing list: http://w3-org.9356.n7.nabble.com/Limited-DOM-in-Web-Workers-td44284.html And the excerpt that answers why there is no access to the XML parser or DOM parser in the Web Worker: You’re assuming that none of the DOM implementation code uses any sort of … Read more

Global variable in Web worker

Web Workers don’t have a window object. To access global state, use self instead, code that will work on both the main thread and the worker thread. But note that you still won’t be able to access or manipulate the parent DOM (e.g. get window.jQuery via self.jQuery). While the main thread window self points to … Read more

Web Workers handling AJAX calls – optimisation overkill?

I have created a proper benchmark for that on jsperf. Depending on the browser, WebWorker approach is 85-95% slower than a raw ajax call. Notes: since network response time can be different for each request, I’m testing only new XMLHttpRequest() and JSON.parse(jsonString);. There are no real AJAX calls being made. WebWorker setup and teardown operations … Read more