Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web worker won't start in IE unless the cache is cleared

I'm having a really weird bug in my HTML5 script. I wrote a sharepoint app completely in OData which uses a few HTML 5 webworker to do the number crunching in the background. This works perfect on all major browsers (FF, IE10+ Chrome, ...). However, when I perform a refresh or browse to the page again. The script still works as intended on FF and Chrome, but hangs on IE.

In my network view I see a request for the Worker.js file, but with a 304 NOT MODIFIED response. IE then just hangs there on that request with a status of (Pending). This issue only gets resolved when I clear my browser cache.

I correctly close all my threads with self.close().

Any idea what the issue could be? I'm not sure if it's a code issue, a browser issue or a server side issue but I can replicate the bug on Sharepoint online as well as on a local server. The whole project is JS only, so I can't modify headers as a workaround either.

UPDATE: I ran exactly the same code outside of a sharepoint environment, and it worked perfectly. Issue is Sharepoint related.

like image 484
Glenn Vandamme Avatar asked Mar 17 '14 13:03

Glenn Vandamme


People also ask

Can Web worker be restarted?

Stopping Web Workers terminate(); A terminated Web Worker will no longer respond to messages or perform any additional computations. You cannot restart a worker; instead, you can create a new worker using the same URL.

Will the Web workers work if we open the file locally with a file scheme?

The script must be served from the same host or domain for security reasons, and that is also the reason that web workers won't work if we open the file locally with a file:// scheme.

How do I create a Webworker in the same file?

You can create a single JavaScript file that is aware of its execution context and can act as both a parent script and a worker. Let's start off with a basic structure for a file like this: (function(global) { var is_worker = ! this.

Where should you place JavaScript code to run in the context of a web worker?

You can run whatever code you like inside the worker thread, with some exceptions. For example, you can't directly manipulate the DOM from inside a worker, or use some default methods and properties of the window object.


2 Answers

using a time based querystring parameter prevents caching showing http status 200 on each refresh. tested on latest chrome, ie, ff;

var opus = new Worker("worker.js?q=" + new Date().getTime().toString() );

to be honest this a long shot as i do not have sharepoint right now

like image 107
ajayel Avatar answered Oct 20 '22 21:10

ajayel


SharePoint sends the header:

Content-Disposition: attachment; filename="xyz.js"
X-Download-Options:  noopen

and the IE Web Worker Implantation then does not run this web worker. (Tested in IE11) In the IE Network Monitor the request still on pending, even the Response text is visible.

I know so fare two workarounds:

  1. Place the web worker js in the layouts folder (needs a Farm Solution, with the downside of this)
  2. Set the Browser File Handling for the Web application to Permissive (maybe your security is not amused)
like image 40
sschoof Avatar answered Oct 20 '22 23:10

sschoof