I have it now working by redesigning my application. Every time the user returns from the configuration window (where he can compose the toolbox), I reload all Blockly libraries in the correct order. This way the Blockly plugin code will be loaded without problems, since the CSS can still be changed (because the workspace is only created afterwards).
var
lastScriptToLoad;
// Remove all the custom blockly scripts from the previous time.
// We can recognize the blockly scripts by the user attribute "data-custom_blockly_library" which we have set below in the code.
$('script[data-custom_blockly_library=true]').remove();
// Make sure that all standard Blockly library files are loaded FIRST AND IN THE CORRECT ORDER, and then the custom block libraries and translations.
// The en.js file should be loaded before the blocks_compressed.js library, to avoid "No message string for..." console warnings.
var resources = [
"blockly-contrib/npm/blockly/blockly_compressed.js", // Creates a global Blockly variable
"blockly-contrib/npm/blockly/msg/en.js", // Fills the Blockly.Msg with english translations
"blockly-contrib/npm/blockly/blocks_compressed.js",
"blockly-contrib/npm/blockly/javascript_compressed.js"
]
// Now add all other required resources to the resources array (i.e. libraries and translation files that the user has been selected)
...
// As soon as the toolbox files have been loaded, the javascript files for the categories will be loaded.
// The javascript files will be loaded synchronous, because there is a dependency order that needs to be fullfilled.
// However the files will be loaded in background, so we need to wait for an event that indicates that the script is loaded...
resources.forEach(function(resource) {
// Make sure that all Blockly library files are loaded in the correct order.
lastScriptToLoad = document.createElement('script');
lastScriptToLoad.type="text/javascript";
lastScriptToLoad.async = false; // Force synchronous loading, to load them in the correct order
lastScriptToLoad.src = file;
// Set a user attribute on the script element, to allow us to identify this script afterwards as one of the blockly related libs
lastScriptToLoad.dataset.custom_blockly_library = true;
document.head.appendChild(lastScriptToLoad);
}
});
});
// The workspace can only be created when all script files have been loaded, otherwise errors will occur...
lastScriptToLoad.onload = function() {
// From here on the global Blockly variable exists, so you can optionally do some initialization here. For example:
Blockly.JavaScript.addReservedWords(['msg', 'flow', 'context', 'global']);
// Create a new XML toolbox document
// Add the toolbox.xml files of all required libraries (which the user has selected to display) via toolboxXmlDocument.documentElement.appendChild(...)
...
// Create the workspace as soon as the last script has been loaded.
...
}
So for me this problem is solved ...
Bart