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
  • 238,746
  • 336
  • 750
  • 1,061

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
  • 63,850
  • 5
  • 53
  • 80