PDA

View Full Version : Can js scripts be combined?



kuau
08-12-2009, 03:20 AM
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:


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


<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:


<script type="text/javascript" src="../js/filename1.js"></script>

Would it still work? Sorry for the dumb question. Thanks. :)

davelf
08-12-2009, 05:06 AM
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:




<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,:)

kuau
08-12-2009, 08:11 AM
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! :)

davelf
08-12-2009, 09:08 AM
thx too for your dumb question, :D. i've never think about it before, your post here make me think about possibility in scripting:)