Load Dart Script if Dartium, Otherwise Load JavaScript in Browser

Assume that we write a dart script called app.dart, and the corresponding compiled JavaScript file is called app.js. We want the browser to load app.dart if the browser supports dart, otherwise load app.js for compatibility. How do we do?

Put the following code in your html before the end of body tag.

<script type='text/javascript'>
  var script = document.createElement('script');
  if (navigator.userAgent.indexOf('(Dart)') === -1) {
    // Browser doesn't support Dart
    script.setAttribute("src", "app.js");
  } else {
    script.setAttribute("src", "app.dart");


[1]Dynamically loading an external JavaScript or CSS file
[2]Detect language unavailability - Synonyms - Dart, JavaScript, C#, Python