Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Web Worker `importScripts` method access scripts cached by the main thread?

Multiple questions actually:

  • Will importScripts always load the scripts with a GET request or can it cache scripts?

  • Can importScripts access scripts cached in the main thread or browser context?

  • Can the worker cache scripts for the main thread to access? (simply the other way around)

like image 211
bennedich Avatar asked Jan 19 '12 00:01

bennedich


1 Answers

  1. importScripts will not load the script again if you specify http cache headers like 'Expires' or 'Cache-control' properly, see google recomendations about that

  2. There is a kind of 'gateway filter' between threads, that allows primitives like booleans, strings to go through but not objects/functions. If you load your script via XHR as a string in main thread, you'll probably be able to send it to the worker thread and eval there.

  3. See the answer #1

like image 102
Ilya Kharlamov Avatar answered Sep 24 '22 12:09

Ilya Kharlamov