html – Configurable ASP.NET Core MVC Localization (ECMAScript Internationalization API)


I have some problems with localization of an ASP.NET Core MVC website.

I tried to Implement ECMAScript Internationalization API

The Problem I have is that the base Software needs to support dozens of localization and it all Loads on the Page although the Customer individually sold versions only need to support 2-4 Localisations.

My Attempt to Reduce the Page “size” was to make the provided Languages configurable. My Controller that reads the config and the Clint side call to add the JS localization files work as Intended.
But my Website already fails to load before the localization files are added. Is there a way to Pre build my html header dynamically, based on Controllers?

Default Implementation of localization:

<html>
    <head>
        ...
        <script src="https://stackoverflow.com/~/js/devextreme/localization/dx.messages.en.js"></script>
        <script src="~/js/devextreme/localization/dx.messages.de.js"></script>
        <script src="~/js/devextreme/localization/dx.messages.ru.js"></script>
    
        <script src="~/js/localization/DataNavigator.messages.en.js"></script>
        <script src="~/js/localization/DataNavigator.messages.de.js"></script>
        <script src="~/js/localization/DataNavigator.messages.ru.js"></script>
    </head>

My Attempt for Configurable Localization:

<html>
    <head>
        ...
    <script>
    $.ajax({
            type: "Get",
            url: '@Url.Action("GetLocalisationFiles", "Localisation")',
            asyc: false,
            success: function (response) {
                for (var prop in response) {
                    var item = response(prop);
                    var s = document.createElement('script');
                    s.setAttribute('src', item);
                    document.head.appendChild(s);
                }
            }
    });
    </script>
</head>

with Browser-page Inspector both headers look the same.
but code in body fails with my version : /

The Approach to localise everything over direct Controller Calls seems a bit too much Communication. I would love the ECMAScript Internationalization API Approach Configurable without any needs to change something in the Software