Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

importScripts failing in ie9 #66

Closed
Fresheyeball opened this issue Jul 10, 2013 · 10 comments
Closed

importScripts failing in ie9 #66

Fresheyeball opened this issue Jul 10, 2013 · 10 comments

Comments

@Fresheyeball
Copy link
Contributor

I am having two problems with the current release of communist and ie9

  1. When using importScripts js dies silently. When wrapping importScripts in a try catch I get : ReferenceError: 'importScripts' is undefined
  2. .then of the promise is not getting called in ie9 depending on the wrapper function. This one is hard to describe. Here is some coffeescript from my project

which produces the following logs in ie9

   i am the worker 2 
   7 
   i am the worker 3 
   8 
   chart update recieved 
   i am the worker 4 
   chart update recieved 
   i am the worker 4 
@calvinmetcalf
Copy link
Owner

I've known about this one for a while, but couldn't figure out how to fix it, meaning I should really document it, the workaround for ie9 at the moment is to put a script tag in the body conditionally commented to only work in ie9 e.g.

<!--[if IE 9]>
<script src="url''></script>
<![endif]-->

this is not ideal, but anything that involves programmaticly putting the script in is going to have trouble guaranteeing that the script is downloaded when it's needed.

@calvinmetcalf
Copy link
Owner

ok realized there were 2 questions here that one I'll get back to you on, though I will point out that console.log inside a worker will explode in everywhere except IE9

@Fresheyeball
Copy link
Contributor Author

I realize about the console.log outside of IE9, I just put it there for debugging.

As for the IE9 conditional comment, I intend on using that script outside of webworkers as well, but at the moment its served for non-webworkers as part of a bundle. Are you ultimately saying that importScripts is defined, but that the script it references is not defined? Could I just serve that script to my whole application outside the bundle and satisfy IE9? If so, I wonder why the browser reported this error the way it did, because its just sounding like the importScripts function is missing.

@calvinmetcalf
Copy link
Owner

So it isn't actually failing silently it's passing an error to the onRejected function of the promise

cw(function(){
  inportScript('blah');
  return 9;
}) .then(function(a){
  console.log('yes ',a);
},function(a){
  console.log('no ',a);
});

prints LOG: no ReferenceError: 'inportScript' is undefined for me, my solution to this which I've used is to put my imports into the initialize function so that I don't care if it fails and then make sure the functions are also in the global scope

@Fresheyeball
Copy link
Contributor Author

I had not tested the silent failing of importScripts, but I certainly believe you. However I feel for communist to polyfill for ie9 importScripts should not be undefined. Should probably detect the absense of webworkers as a feature and define importScripts as something akin to $.getScript

@calvinmetcalf
Copy link
Owner

the key is to do it in a way that ( in this order)

  1. is usable with the current api (aka more or less sync creation wise)
  2. avoids polluting the global name space if possible

I think I'm going to have to use the stringification I use to make the worker on the stuff for ie9 and then manipulate the text before evaling it,

In the mean time instead of

cw(function(a){
  inportScript('blah');
  whatever
})

write

cw({
  init:function(){
    inportScript('blah');
  },
  data:function(a){
    whatever
  }
})

this also gets around the bug in #59

@calvinmetcalf
Copy link
Owner

i realize now I wrote inportScripts instead of importScripts when I was testing it on IE9 I need to retest tomorrow.

@calvinmetcalf
Copy link
Owner

you have no idea the levels of black magic to get import scripts to work in ie9

@Fresheyeball
Copy link
Contributor Author

Um... do tell?

@calvinmetcalf
Copy link
Owner

as of v1.7.1 it uses the same procedure to turn the functions into a string in ie9 as in other ones, and then uses the same regex to move the scripts out of the main function, but then also regexes any function declaration inside the main object into function expressions, downloads the imported scrips via ajax, concats it all together and evals it. meanwhile the fake worker creation happens synchronously with calls to the fake worker queued up until after they all download. It's in pull #76.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants