tgvashworth / ServiceWorker-Polyfill

[DEPRECATED] JavaScript ServiceWorker implementation, enabling exploration by authors.
66 stars 7 forks source link

importScripts #5

Closed tgvashworth closed 10 years ago

tgvashworth commented 10 years ago

Implementation options:

or

Second one for me.

jakearchibald commented 10 years ago

The first implementation sounds like the best thing. However, importScripts should throw if it's called after the initial execution of worker.

importScripts shouldn't make a network request once the serviceworker has installed, imported scripts should be put in a special cache.

Related: https://github.com/slightlyoff/ServiceWorker/issues/106

tgvashworth commented 10 years ago

Seems like the best method here would be a combination of both:

tgvashworth commented 10 years ago

But, this isn't such a great method if you want to prevent it being called later.

jakearchibald commented 10 years ago

The parsing trick falls over with importScripts(variable).

What's the benefit of calling importScripts later than initial execution?

tgvashworth commented 10 years ago

Not sure what you mean – you can get the variable out no problem.

The problem with not doing an AST parse is that, afaik, there's no way to pause function execution while node does a network request and have the fetched code execute in the same scope as the worker.

jakearchibald commented 10 years ago

Not sure what you mean – you can get the variable out no problem.

var whatever = 'foo';

if (version > 4) {
  whatever = 'bar';
}

importScripts(whatever);

or

importScripts(whatever + Math.random());

The problem with not doing an AST parse is that, afaik, there's no way to pause function execution while node does a network request and have the fetched code execute in the same scope as the worker.

Oh, there isn't a way to make a sync network request? Sheeeeet

jakearchibald commented 10 years ago

You're not going to like it, but here's how the xmlhttprequest lib does sync requests https://github.com/driverdan/node-XMLHttpRequest/blob/master/lib/XMLHttpRequest.js#L454

tgvashworth commented 10 years ago

Eurgh, yeah. Fair enough. @ahume's working on this atm.

ahume commented 10 years ago

Think this is more or less there. Reopen if not.