how to include javascript libraries in my own script

18,357

Solution 1

There are a lot of tools around though they seem overkill for what you have to do.

I think your best bet would be to take those files and copy paste them into one single file.

If you want to use a tool, since you require it (and its complexity :D) then I would recommend trying out grunt, it is easy to set up and if you'll ever need to expand it to suit further needs it will be almost hassle free, for example, to concatenate:

grunt.initConfig({
  concat: {
    dist: {
      src: ['libs/first.js', 'libs/second.js'],
      dest: 'out/first-and-second.js'
    }
  }
});

Solution 2

There are multiple tools that do what you want:

http://requirejs.org/

https://developers.google.com/closure/compiler/

Share:
18,357
Stijn De Schutter
Author by

Stijn De Schutter

Updated on June 04, 2022

Comments

  • Stijn De Schutter
    Stijn De Schutter about 2 years

    I have written some functions in javascript and I've put them in a separate JS file (visualisations.js). The functions I've written use several other javascript libraries, at the moment these libraries are all included in my HTML page, so I have 7 lines like this

    <script src="JS/jquery-1.9.1.min.js"></script>
    <script src="JS/raphael.2.1.0.min.js"></script>
    <script src="JS/justgage.1.0.1.min.js"></script>
    <script src="JS/jquery-ui.js"></script>
    <script src="JS/jquery.ui.touch-punch.min.js"></script>
    <script src="JS/dygraph-combined.js"></script>
    <script src="JS/visualisations.js"></script>. 
    

    My question: is there a way to include the libraries into my own JS file (visualisations.js) so eventually I only need to include my own JS file in the HTML file and not write 7 lines to include all the libraries.

    Any suggestions? Please keep your answer understandable, I'm no advanced programmer.

    Grtz Stijn