jnordberg / gif.js

JavaScript GIF encoding library
http://jnordberg.github.io/gif.js/
MIT License
4.76k stars 668 forks source link

browser shims #6

Open calvinmetcalf opened 11 years ago

calvinmetcalf commented 11 years ago

I've had some experience with workers doing communistjs here are some things I learned:

jnordberg commented 11 years ago

Thanks, that's some great info! gonna do some experiments with transferable objects now :)

Regarding the worker script path, wouldn't you have the same problem figuring out the path for the worker to call itself? Looking around I also found this but it's not a great solution imo http://stackoverflow.com/questions/2161159/get-script-path

calvinmetcalf commented 11 years ago

this should do the trick

function getPath(){
    var scripts = document.getElementsByTagName("script");
        var len = scripts.length;
        var i = 0;
        while(i<len){
            if(/gif(\.min)?\.js/.test(scripts[i].src)){
               return scripts[i].src;
            }
            i++;
        }
}
calvinmetcalf commented 11 years ago

though this is in coffeescript so

getPath = () ->
  scripts = document.getElementsByTagName("script")
  return script.src for script in scripts when /gif(\.min)?\.js/.test(script.src)
jnordberg commented 11 years ago

Now the worker is transferring data instead of copying, i'm still copying to the worker since i can not guarantee i wont need it again

calvinmetcalf commented 11 years ago

you may want to test if it's internet explorer 10 before doing the transferable object, self.UintClampedArray8 might be a good proxy to check for as IE10 doesn't have that either

jnordberg commented 11 years ago

I actually had some issues in every browser but chrome so now it's only enabled there. Firefox ran without error but the data was corrupted

bendean commented 10 years ago

I'm running in Angular.js and it's unable to load the worker script, since my index.html is in the root so it's looking for /gif.worker.js (while actual .js is in /assets/gif.js/...

Any solution for this? I'm not clear on the typeof document === "undefined" solution above, if you can shed more insight.

calvinmetcalf commented 10 years ago

The issue is if you have script.js and worker.js if they are both in the root everything is fine but if you move them both into assets then you have to modify the path in script to tell it to lead it from assets.

The typeof document idea is that is you combine the script and worker into one file with checking for document being the switch.

The key here is that the script goes through the script tags in the page to figure out what the path of itself is in order to load itself, likely you either renamed the script, or didn't import it through a script tag (this is based on having zero memory of what gif.js ended up doing I may be way off) On Jun 27, 2014 4:48 PM, "Ben Dean" notifications@github.com wrote:

I'm running in Angular.js and it's unable to load the worker script, since my index.html is in the root so it's looking for /gif.worker.js (while actual .js is in /assets/gif.js/...

Any solution for this? I'm not clear on the typeof document === "undefined" solution above, if you can shed more insight.

— Reply to this email directly or view it on GitHub https://github.com/jnordberg/gif.js/issues/6#issuecomment-47398469.