[Bug] Loading monaco via require doesn't always respect urlArgs parameter
Reproducible in vscode.dev or in VS Code Desktop?
- [X] Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- [X] Not reproducible in the monaco editor playground
Monaco Editor Playground Link
No response
Monaco Editor Playground Code
No response
Reproduction Steps
No response
Actual (Problematic) Behavior
No response
Expected Behavior
No response
Additional Context
We have been using the AMD style to load the monaco editor in the browser.
It works mostly well but we are running into an issue.
Monaco being a fairly large library, we want to load the library lazily. To improve performance, we also want to use HTTP caching heavily to avoid users having to reload the monaco files unnecessarily.
To achieve this, we used the code from the AMD sample and simply added the urlArgs parameter in the require.config call.
Requirejs docs:
Below is the same code as in the sample, with the added urlArgs: "v=0.35.0" so that the version parameter is added to all fetch requests
<script src="monaco-editor/min/vs/loader.js"></script>
<script>
require.config({ paths: { vs: 'monaco-editor/min/vs' }, urlArgs: "v=0.35.0" });
require(['vs/editor/editor.main'], function () {
var editor = monaco.editor.create(document.getElementById('container'), {
value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
language: 'javascript'
});
});
</script>
Since we don't use requirejs for anything else, we use the provided vs loader.js
What we found is that it works well for the initial files but not all subsequent files. Below you can see a screenshot from the Chrome network requests. The urlArgs parameter is correctly added to the editor.main.* files. However the workerMain.js url appends the query param twice and, more importantly, no param is added to simpleWorker.nl.js
Is this a known issue? Can a fix be released?
Is this a known issue?
Not that I know of.
Can a fix be released?
Unfortunately, I cannot look into this at the moment. Can you try to investigate the issue? Maybe it makes sense to use the ESM version or use your own loader?
To be honest I'm not sure how to investigate this issue. We don't use AMD or requirejs anywhere else. Only for Monaco. I have even less clue how to use the ESM version or implement my own loader. But isn't the built-in monaco loader supposed to work? Any chance it could be fixed to honour the urlArgs? Alternatively, is there any other recommended technique to bust the cache and ensure that the browser doesn't end up using cached files from previous monaco versions?
Alternatively, is there any other recommended technique to bust the cache and ensure that the browser doesn't end up using cached files from previous monaco versions?
Maybe you can include the monaco editor version number in the path of the monaco editor dist files?
@hediet thanks for the suggestion. I'll try and report back.
I don't understand what an editor is supposed to do here, could you please explain? @hediet