473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Pros/Cons to loading Javascript inside the BODY tags?

I have a need to load javascript functions for various parts of our site.

Normally, when making a page, we link to the javscript function within the
HEAD tags and reference them as needed within the contents of the page.

However, all of our content is being loaded by a user control already within
the BODY of our page.

What's the best way to handle this?

Should the UC that loads within the body tag somehow communicate with the UC
that loads the links in the HEAD tags to let it know that we need a
particular .js link? If so, what's the best way to pass that info to that
UC? I could just have that UC query the DB as well, but 99% of the time,
that'd be a pointless thing, as usually we wouldn't need a .js link up there
(of course, this would be an easy solution to implement).

Alternatively, any reason to not just load the .js that is needed within the
BODY of the page itself?

-Darrel

--
================================================== ===============
Win prizes searching google:
http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA
Nov 17 '06 #1
1 1172
in your usercontrol you should be registering the script you need:
if (!cm.IsStartupScriptRegistered("keyofscript"))
{
cm.RegisterClientScriptBlock(this.Page.GetType(),
"keyofscript","pathtojsfile");
}
the check is to make sure that if you drag multiple controls (or even
other controls dependent on the same js file), it will only be loaded
once.
i've found very few situations where the js needs to actually be in the
<head>, and even the framework doesn't do that for you. there are some
situations where i just needs to be there, and in those rare cases, i
hardcode the js link in the master page <headsection
On Nov 17, 8:48 am, "darrel" <notr...@nowhere.comwrote:
I have a need to load javascript functions for various parts of our site.

Normally, when making a page, we link to the javscript function within the
HEAD tags and reference them as needed within the contents of the page.

However, all of our content is being loaded by a user control already within
the BODY of our page.

What's the best way to handle this?

Should the UC that loads within the body tag somehow communicate with the UC
that loads the links in the HEAD tags to let it know that we need a
particular .js link? If so, what's the best way to pass that info to that
UC? I could just have that UC query the DB as well, but 99% of the time,
that'd be a pointless thing, as usually we wouldn't need a .js link up there
(of course, this would be an easy solution to implement).

Alternatively, any reason to not just load the .js that is needed within the
BODY of the page itself?

-Darrel

--
================================================== ===============
Win prizes searching google:http://www.blingo.com/friends?ref=hM...nTqhv-2GE1FNtA
Nov 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: vincent_delft | last post by:
I'm looking for a Web Tool kit to build web pages with the following criteria (in priority order) : - easy to use, develop (reuseability of code, ...) - flexible (ideally should run with Python...
3
by: stan k. | last post by:
First of all let me clarify - I am not talking about having a bunch of images loaded all at once (or preloaded) and then controlling the display of the images after that point -- I know that can be...
77
by: Tim Anderson | last post by:
I've begun to set down some pros and cons here: http://www.itwriting.com/phorum/list.php?f=6 Thought I'd mention it as it's a topic of such enduring interest :-) Tim
5
by: joaopedrogoncalves | last post by:
Hi, I want to load an external javascript file, get its results and stick them inside a <div> block. I also want to do this in several places on a web page. This way the browser doesn't have...
5
by: Tudor Tihan | last post by:
Hi, This is my first post here, so please be kind. I have tryed to make a javascript html page loader by using an invisible <IFrame> and some javascript variable text passing between...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
3
by: Andrea | last post by:
Hello everyone, I'd like to know which are the main pros and cons of using XML implementation in business organizations. >From a technical perspective, I find XML powerful, but looks like it is...
9
by: loretta | last post by:
This code is just reading html and printing , eventually I want to modify the html. However, the original html contains javascript and the output html contains tags not in the original. $url =...
13
eragon
by: eragon | last post by:
JavaScript Loading Mask Requirements: Little knowledge in JavaScript and some HTML. JavaScript enabled browser. Applications: Useful for all those pages that load slow, and in sections, so...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.