mardi 28 mars 2017

I want to provide callback when clients load a javascript bundle library using snippet

my javascript library product is loaded asynchronously through the snippet in the client html.

As follows...

<html>
<head> ... </head>
<body>
    <script>

    ...

    !function(e,t){function n(e,t){
        ...
        // loads javascript bundle library from server
        ...
    }}(document, window.MYPRD||[]);

    ...

    </script>

    <script>

    // if bundle library is not loaded, the following code will return an error since MYPRD object and myFunc() is not defined.
    MYPRD.myFunc()

    </script>
</body>
</html>

However, the snippet in that script tag is executed asynchronously and loads the bundle, so a callback function might be needed to ensure order when there are another executable codes in html.

I would also like to know how to guarantee the order from the client html using a load function, but I wish I could solve this issue in my snippet or my JavaScript bundle library.

What should I do? Please explain in detail. (I am a beginner in Javascript and web development.)

Thank you.




Aucun commentaire:

Enregistrer un commentaire