Reconsider approach of using script dependencies to opt-in a script for worker offloading #1468
Labels
[Plugin] Web Worker Offloading
Issues for the Web Worker Offloading plugin.
[Type] Enhancement
A suggestion for improvement of an existing feature
Currently the way that a script is offloaded to a web worker is to add the
web-worker-offloading
script dependency:To opt-in existing scripts:
However, I just realized a significant problem: if someone deactivates the Web Worker Offloading plugin, then the
web-worker-offloading
script won't be registered and so the script having it asa dependency won't get printed at all. This would then necessitate having to add conditional checks like the following before doing the above code:We could make this more resilient by taking a similar approach to what we did with the script loading strategies (async/defer). In fact, offloading to a web worker could itself be considered a type of loading strategy. With script loading strategies, we utilize the
strategy
key for script data. So for example an existing script can be opted-in to theasync
strategy:We could do something similar for offloading to a worker, for example:
Then when scripts are being printed, we could check if any of the pending handles have a
worker
script data key with atrue
value, and if so, print the Partytown script as well as add thetype="text/partytown"
attribute to the script being printed.The text was updated successfully, but these errors were encountered: