Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Including a script src into js file [duplicate]

Im trying to integrate a firebase config into my js file rather than directly into html file. Given:

<script src="https://www.gstatic.com/firebasejs/3.4.0/firebase.js"></script>
<script>
  // Initialize Firebase
  var config = {
  .......
  }
</script>

and my js file:

$(function() {
......
}

how can I integrate the line <script src="https://www.gstatic.com/firebasejs/3.4.0/firebase.js"></script> into my js file ?

like image 404
Mike Avatar asked Jan 05 '23 07:01

Mike


1 Answers

You can create a tag script and append to body of document.

var script = document.createElement('script');
    script.type = 'text/javascript';

    script.src = 'https://www.gstatic.com/firebasejs/3.4.0/firebase.js';
    document.body.appendChild(script);
like image 93
cesare Avatar answered Jan 13 '23 09:01

cesare