5

Inside one of my views, I'd like to load this script:

<script type="text/javascript" src="https://domain.com" id="hello" name="abc"></script>

Is it possible to do that?

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

1 Answers1

5
  1. Manually appending it:

    $('head').append('<script type="text/javascript" src="https://domain.com" id="hello" name="abc"></script>')
    
  2. Using $.getScript:

    $.getScript('https://domain.com').done(function () {
        // loaded!
    });
    
  3. RequireJS:

    require.config({
        paths: {
            "myscript": "https://domain.com"
        }
    });
    
    require(['myscript'], function () {
        // loaded!
    });
    
jgillich
  • 71,459
  • 6
  • 57
  • 85