Combine <script> in .js file

Discussion in 'JavaScript' started by Rajnish357, Feb 17, 2012.

  1. #1
    I have multiple scripts like

    <script>
    .....
    </script>

    <script>
    .....
    </script>

    <script>
    .....
    </script>

    I want to move them all in a .js file can anyone help ?
     
    Solved! View solution.
    Rajnish357, Feb 17, 2012 IP
  2. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #2
    copy the contents of each <script> then paste it in the js file you will be creating..
     
    JohnnySchultz, Feb 17, 2012 IP
  3. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #3
    If you have multiple .js files like this:

    
    <script>
    This is the content of the 1st file
    </script>
    
    <script>
    This is the content of the 2nd file
    </script>
    
    <script>
    This is the content of the 3rd file
    </script>
    
    HTML:

    Just put all the contents into one .js file like this:
    
    <script>
    This is the content of the 1st file
    
    This is the content of the 2nd file
    
    This is the content of the 3rd file
    </script>
    
    HTML:
     
    Andre91, Feb 17, 2012 IP
  4. Rajnish357

    Rajnish357 Well-Known Member

    Messages:
    157
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    I tried but it did not worked !!

     
    Rajnish357, Feb 20, 2012 IP
  5. #5
    EricBruggema, Feb 21, 2012 IP
  6. Rajnish357

    Rajnish357 Well-Known Member

    Messages:
    157
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #6
    Rajnish357, Feb 29, 2012 IP
  7. trendint

    trendint Peon

    Messages:
    52
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Do note that if you have a heavily traffic site that this is a potential bottleneck. You are requiring your webserver to spin up an instance of PHP and perform multiple disk reads to generate a single output file. You should use something like this to generate a single file that you still add in to the HTML for a normal script include - if you are concerned about the overhead that is - and this overhead is minimal if you are dealing with low traffic.
     
    trendint, Feb 29, 2012 IP