Results 1 to 4 of 4

Thread: Can js scripts be combined?

  1. #1
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default Can js scripts be combined?

    I'm wondering if it is necessary for each script to repeat the script definition tags. For example, say you have 2 scripts in your head section right after each other, such as:

    Code:
    <script type="text/javascript" src="../js/filename1.js"></script>
    <script type="text/javascript" src="../js/filename2.js"></script>
    Could you combine them as follows:

    Code:
    <script type="text/javascript" src="../js/filename1.js"
    src="../js/filename2.js"></script>
    Or if that is not possible, could you take the text of filename2 and append it to the bottom of filename1 and then just have:

    Code:
    <script type="text/javascript" src="../js/filename1.js"></script>
    Would it still work? Sorry for the dumb question. Thanks.

  2. #2
    Join Date
    Jul 2009
    Location
    Binus University
    Posts
    456
    Thanks
    76
    Thanked 21 Times in 21 Posts

    Default

    i don't think it's gonna work, when u open a page just try to view the page source, you'll find not only one js but a lot, like this page, when u see the page source it's will show like this:

    Code:
    <script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/yahoo-dom-event/yahoo-dom-event.js?v=381"></script>
    
    <script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/connection/connection-min.js?v=381"></script>
    <script type="text/javascript">
    
    <script type="text/javascript" src="clientscript/vbulletin_global.js?v=381"></script>
    
    <script type="text/javascript" src="clientscript/vbulletin_menu.js?v=381"></script>
    i think it's because combine one js in one line, it's make the js crash.

    i'm sorry too for my dumb answer,

  3. The Following User Says Thank You to davelf For This Useful Post:

    kuau (08-12-2009)

  4. #3
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    602
    Thanks
    266
    Thanked 13 Times in 13 Posts

    Default

    Dear Davelf:

    Thanks for the "dumb" answer haha I figured it was probably not possible. Maybe there is some kind of rule in javascript that each script must stand on its own within the tags, unlike php. I understand php a lot better than javascript.

    Thanks!

  5. The Following User Says Thank You to kuau For This Useful Post:

    davelf (08-12-2009)

  6. #4
    Join Date
    Jul 2009
    Location
    Binus University
    Posts
    456
    Thanks
    76
    Thanked 21 Times in 21 Posts

    Thumbs up

    thx too for your dumb question, . i've never think about it before, your post here make me think about possibility in scripting

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •