How does js load on demand?

threejs needs to call too many js when building a scene, how to load it on demand?

tried requirejs, but didn"t feel quite in demand.

for example, to build a material, you need to import about 10 + js, but this material is not used initially (such as switching the display requirements of the material)
how to load the 10 + js? when it can be used.

Mar.30,2021

Native js can be loaded on demand by dynamically creating script tags.

if you are using react , you can use react-loadable this library to implement

.

requirejs seajs


require(['jquery'], function ($) {
    $(function () {
        //knockoutjs
        $("-sharptest").click(
            function () {
                require(['knockout'], function (ko) {
                    alert(ko.version);
                });
            }
        );
    });
Menu