Search code examples
javascriptcdn

Load external library from CDN under an alias


I need to load two versions of the same library from CDN. Is there a way to specify the name of the resulting object on window so that they don't clash? Or can I rename the first before the second loads?


Solution

  • <script src="lib@1" />
    <script> window.lib1 = window.lib; </script>
    <script src="lib@2" />
    

    then

    window.lib1 // is lib@1
    window.lib  // is lib@2