I have a webapp where I have to show the ace editor in multiple places. So I have a common routine that loads the ace editor with a given root element (code in coffee)
editor = window.ace.edit(root)
editor.setTheme("ace/theme/github")
editor.getSession().setMode("ace/mode/json")
The issue I have is that every time I set the mode, the json-worker is fetched from the server. It seems setting the mode initiates the web worker and the web worker has to be fetch the code from a url.
I have tried caching an instance of the mode and setting that but that does not seem to change the behavior at all.
Is there any way to make the worker js load once and then reuse it in subsequent uses, without reloading it from the server?
This isn't possible since every session creates it's own worker. Loading source code of worker in the main thread as text, and using that to create blob object will be hacky and less performant than loading it multiple times in a worker. If you are only concerned about network fetch, try setting proper cache headers for that file. If you want only one worker for all editors, you have to modify ace. You can use github to create feature or pull request.