Late load of kernel.js

Hi. I’m defining custom codemirror mode inside kernel.js in custom kernel. However kernel.js seems to be loaded asynchronously, so sometimes all the rendering happening before kernel.js is loaded and custom mode will not be used. To fix that behavior I do following stuff after load:

IPython.CodeCell.options_default["cm_config"]["mode"] = "tlaplus";

[...document.querySelectorAll('.code_cell .CodeMirror')].forEach(c => {
    c.CodeMirror.setOption('mode', 'tlaplus');

Jupyter.notebook.get_cells().forEach(function(c) {
    if (c.cell_type == "code") {
        c._options.cm_config['mode'] = 'tlaplus';

However it is quite a kludge and also do not work with blocks of code inside markdown. Is there any better way to fight late kernel.js load?

Also frontend seems to always ask about default mode and unsurprisingly always gets 404. Any way to suppress that?