473,411 Members | 2,031 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,411 software developers and data experts.

Do <script tags have to appear in <head section?

Hi

I am new to javascript. I have a website running in .net, that has a
load of these in the <head section of the default.aspx page, which
bumps the page size up to 371kb. However, many of these are only used
in one 'skin', or page in the system. Is there any way I can put these
scripts elsewhere, so they are only loaded when they are needed. Then
every webpage will not have to be so enormous?

This is the sort of thing I am talking about:

<script type="text/javascript" src="<%= Page.ResolveUrl("js/
swfobject.js") %>"></script>

Stapes

Oct 11 '07 #1
15 2196
Stapes vient de nous annoncer :
Hi

I am new to javascript. I have a website running in .net, that has a
load of these in the <head section of the default.aspx page, which
bumps the page size up to 371kb. However, many of these are only used
in one 'skin', or page in the system. Is there any way I can put these
scripts elsewhere, so they are only loaded when they are needed. Then
every webpage will not have to be so enormous?

This is the sort of thing I am talking about:

<script type="text/javascript" src="<%= Page.ResolveUrl("js/
swfobject.js") %>"></script>

Stapes
using this method, you just download the .js file once, and every time
your code uses it, the browser looks for it in the client cache no?

take a look at this

http://www.fiddlertool.com/fiddler/

its a html debugger

you can get information about all the traffic and times of your pages,
forms and a lot of things
Oct 11 '07 #2
On 11 Oct, 10:40, matatunos <matatu...@gmail.comwrote:
Stapes vient de nous annoncer :
Hi
I am new to javascript. I have a website running in .net, that has a
load of these in the <head section of the default.aspx page, which
bumps the page size up to 371kb. However, many of these are only used
in one 'skin', or page in the system. Is there any way I can put these
scripts elsewhere, so they are only loaded when they are needed. Then
every webpage will not have to be so enormous?
This is the sort of thing I am talking about:
<script type="text/javascript" src="<%= Page.ResolveUrl("js/
swfobject.js") %>"></script>
Stapes

using this method, you just download the .js file once, and every time
your code uses it, the browser looks for it in the client cache no?

take a look at this

http://www.fiddlertool.com/fiddler/

its a html debugger

you can get information about all the traffic and times of your pages,
forms and a lot of things
Surely an http debugger?

Oct 11 '07 #3
On 11 Oct, 10:40, matatunos <matatu...@gmail.comwrote:
Stapes vient de nous annoncer :
Hi
I am new to javascript. I have a website running in .net, that has a
load of these in the <head section of the default.aspx page, which
bumps the page size up to 371kb. However, many of these are only used
in one 'skin', or page in the system. Is there any way I can put these
scripts elsewhere, so they are only loaded when they are needed. Then
every webpage will not have to be so enormous?
This is the sort of thing I am talking about:
<script type="text/javascript" src="<%= Page.ResolveUrl("js/
swfobject.js") %>"></script>
Stapes

using this method, you just download the .js file once, and every time
your code uses it, the browser looks for it in the client cache no?

take a look at this

http://www.fiddlertool.com/fiddler/

its a html debugger

you can get information about all the traffic and times of your pages,
forms and a lot of things
Sorry - I don't see the relevance of your answer

Oct 11 '07 #4
>>
>using this method, you just download the .js file once, and every time
your code uses it, the browser looks for it in the client cache no?

take a look at this

http://www.fiddlertool.com/fiddler/

its a html debugger

you can get information about all the traffic and times of your pages,
forms and a lot of things

Sorry - I don't see the relevance of your answer
sorry, i have not read correctly the original post, my native language
is spanish not english.

answering to Captain Paralytic

i'm a beguinner in web development, i use firebug with mozilla to get
information about web pages, scripts, gets, posts, xml returned by ajax
etc, with IE6 and IE7, i didnīt find any thing like firebug, and
fiddlertool is a very good tool for me to see why some things are wrong
in my code, performance, headers, broken links, traffic, etc.. its not
a debugger, but helps debugging (the autor say "Web Debugging Proxy")
Oct 11 '07 #5
On 11 Oct, 12:33, RobG <rg...@iinet.net.auwrote:
How does the above address the OP's issue of very large pages?
Well, the following 2 extracts from the referenced page explain this:

The problem
I was wondering how feasible it is to call Javascripts only when you
need them. Basically not to have a load of <script src="js.js">s at
the top of the page, but only those that are actually needed, when
they are needed.
Javascript include on user demand
Now a bit more of a real life example - the javascript is included
when the user performs an action (click).

Oct 11 '07 #6
Stapes <st**********@gmail.comwrote:
>Hi

I am new to javascript. I have a website running in .net, that has a
load of these in the <head section of the default.aspx page, which
bumps the page size up to 371kb. However, many of these are only used
in one 'skin', or page in the system. Is there any way I can put these
scripts elsewhere, so they are only loaded when they are needed. Then
every webpage will not have to be so enormous?

This is the sort of thing I am talking about:

<script type="text/javascript" src="<%= Page.ResolveUrl("js/
swfobject.js") %>"></script>
You're talking about using server-side processing to create a filename
for the src attribute of the script tag? That looks OK to me. By the
time the client gets the page, src has a normal-looking filename in
it, and the client browser will just go and get that file.

--
Tim Slattery
Sl********@bls.gov
http://members.cox.net/slatteryt
Oct 11 '07 #7
On 11 Oct, 14:14, Tim Slattery <Slatter...@bls.govwrote:
Stapes <steve.sta...@gmail.comwrote:
Hi
I am new to javascript. I have a website running in .net, that has a
load of these in the <head section of the default.aspx page, which
bumps the page size up to 371kb. However, many of these are only used
in one 'skin', or page in the system. Is there any way I can put these
scripts elsewhere, so they are only loaded when they are needed. Then
every webpage will not have to be so enormous?
This is the sort of thing I am talking about:
<script type="text/javascript" src="<%= Page.ResolveUrl("js/
swfobject.js") %>"></script>

You're talking about using server-side processing to create a filename
for the src attribute of the script tag? That looks OK to me. By the
time the client gets the page, src has a normal-looking filename in
it, and the client browser will just go and get that file.

--
Tim Slattery
Slatter...@bls.govhttp://members.cox.net/slatteryt
How is that relevant to this discussion?

Oct 11 '07 #8
On 11 Oct, 16:11, Stapes <steve.sta...@gmail.comwrote:
Doesn't work.
"Doesn't work." How helpful. Care to share how it doesn't work? What
actually happens? What are you expecting to happen?

If your function OpenTour() is in the library js/virtualtour.js, then
why not do away with the href="javascript... and just do something
like:

<li><a class="pdflink" href="#" onclick="include_dom('http://www.hotel-
victoria.co.uk/js/
virtualtour.js');OpenTour('beach','beach_medres.ip x');return
false;">Beach</a><br /></li>

Oct 11 '07 #9
On 11 Oct, 12:00, matatunos <matatu...@gmail.comwrote:
using this method, you just download the .js file once, and every time
your code uses it, the browser looks for it in the client cache no?
take a look at this
>http://www.fiddlertool.com/fiddler/
its a html debugger
you can get information about all the traffic and times of your pages,
forms and a lot of things
Sorry - I don't see the relevance of your answer

sorry, i have not read correctly the original post, my native language
is spanish not english.

answering to Captain Paralytic

i'm a beguinner in web development, i use firebug with mozilla to get
information about web pages, scripts, gets, posts, xml returned by ajax
etc, with IE6 and IE7, i didnīt find any thing like firebug, and
fiddlertool is a very good tool for me to see why some things are wrong
in my code, performance, headers, broken links, traffic, etc.. its not
a debugger, but helps debugging (the autor say "Web Debugging Proxy")
And headers, traffic, &c. are not HTML

Oct 11 '07 #10
On 11 Oct, 16:27, Captain Paralytic <paul_laut...@yahoo.comwrote:
On 11 Oct, 16:11, Stapes <steve.sta...@gmail.comwrote:
Doesn't work.

"Doesn't work." How helpful. Care to share how it doesn't work? What
actually happens? What are you expecting to happen?

If your function OpenTour() is in the library js/virtualtour.js, then
why not do away with the href="javascript... and just do something
like:

<li><a class="pdflink" href="#" onclick="include_dom('http://www.hotel-
victoria.co.uk/js/
virtualtour.js');OpenTour('beach','beach_medres.ip x');return
false;">Beach</a><br /></li>
If you go to http://www.hotel-victoria.co.uk/virt...2/Default.aspx
and click on any of the links in the right panel, you will see what it
does when it works.

Oct 11 '07 #11
Captain Paralytic said the following on 10/11/2007 7:47 AM:
On 11 Oct, 12:33, RobG <rg...@iinet.net.auwrote:
>How does the above address the OP's issue of very large pages?
Well, the following 2 extracts from the referenced page explain this:
No, it attempts to explain it without explaining some of the problems
with the method of loading js files on the fly.
The problem
I was wondering how feasible it is to call Javascripts only when you
need them. Basically not to have a load of <script src="js.js">s at
the top of the page, but only those that are actually needed, when
they are needed.
And there is a problem with the approach used in that page that isn't
covered in that page. Namely, instead of a simple alert, try loading a
function in the external .js file and then calling that function. You
will run into a timing issue and that timing issue isn't covered in that
page.
Javascript include on user demand
Now a bit more of a real life example - the javascript is included
when the user performs an action (click).
If the only thing in the external file is an alert, then it will work.
Again, try putting a function in the external file and then calling it:

onclick="include_dom('someFileWithAFunctionInIt'); someFunctionInTheExternalFile()";

Even then, loading files on the fly isn't a solution to the OP's question.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 11 '07 #12
On Oct 11, 3:13 pm, Randy Webb <HikksNotAtH...@aol.comwrote:

[snip]
>
setAttribute is buggy in IE, set the property directly:
It isn't buggy, but broken as designed.
js.type="text/javascript";
This is the same as using setAttribute in IE, which is the whole
problem with IE's implementation. In this particular case it doesn't
make any difference as the element property is a string and the
attribute name is not a reserved word or camel-case.

On the other hand, these will all fail in IE:

el.setAttribute('disabled', 'disabled'); // disabled property is
boolean

el.setAttribute('style', 'color:red'); // style property is an object

el.setAttribute('onclick', 'alert("test");'); // onclick property
needs a function

el.setAttribute('for', 'myID'); // for is reserved, property is
htmlFor

el.setAttribute('maxlength', '10'); // property is maxLength

The getAttribute method has the same botched design. Of course, it is
rarely useful to call getAttribute to retrieve something that is
exposed by a standard DOM property in the first place.

The feature test for this is trivial, but a full workaround is not as
IE does weird things when setting the type property of input
elements. I got tired of the get/setAttribute taboo a while back and
worked out wrappers, but they are not pretty.

It is beyond belief that MS didn't change this in IE7.

Oct 12 '07 #13
David Mark said the following on 10/11/2007 8:20 PM:
On Oct 11, 3:13 pm, Randy Webb <HikksNotAtH...@aol.comwrote:

[snip]
>setAttribute is buggy in IE, set the property directly:

It isn't buggy, but broken as designed.
Agreed.
>js.type="text/javascript";

This is the same as using setAttribute in IE, which is the whole
problem with IE's implementation. In this particular case it doesn't
make any difference as the element property is a string and the
attribute name is not a reserved word or camel-case.

On the other hand, these will all fail in IE:
<snipped examples of IE's broken setAttribute>

That is why I don't use it at all. It is easier to just not use it at
all than it is to try to remember when it will - or won't - work properly.
The feature test for this is trivial, but a full workaround is not as
IE does weird things when setting the type property of input
elements. I got tired of the get/setAttribute taboo a while back and
worked out wrappers, but they are not pretty.
Is there a place that setting the property directly doesn't work?
It is beyond belief that MS didn't change this in IE7.
Totally agreed.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 12 '07 #14
David Mark said the following on 10/11/2007 9:27 PM:
On Oct 11, 8:44 pm, Randy Webb <HikksNotAtH...@aol.comwrote:
[snip]
>Is there a place that setting the property directly doesn't work?

If the corresponding DOM property has problems (like the type property
of input elements), then a working setAttribute (or ugly workaround)
is a necessity.
That would explain why I have never had a need to use it. I have never
tried changing the type of an input element. If I wanted a different
type, I would simply remove the existing and replace it.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 12 '07 #15
Captain Paralytic said the following on 10/11/2007 11:27 AM:
On 11 Oct, 16:11, Stapes <steve.sta...@gmail.comwrote:
>Doesn't work.

"Doesn't work." How helpful. Care to share how it doesn't work? What
actually happens? What are you expecting to happen?

If your function OpenTour() is in the library js/virtualtour.js, then
why not do away with the href="javascript... and just do something
like:

<li><a class="pdflink" href="#" onclick="include_dom('http://www.hotel-
victoria.co.uk/js/
virtualtour.js');OpenTour('beach','beach_medres.ip x');return
false;">Beach</a><br /></li>
Why you shouldn't do something like that is one of the problems I have
mentioned in my other replies in this thread. You run into a timing
issue whereby the file virtualtour.js doesn't have time to download
before OpenTour is executed. You can test it locally and it will usually
"work" because of the loading time. Testing it from a remote server will
usually cause it to fail and IE/FF will throw an error that OpenTour is
not defined (and rightfully so since it isn't defined when you try to
call it).

This is also why I wrote that trying to dynamically load the file a
function in and then execute it is a bad strategy most of the time. In
fact, it is a horrible strategy.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Oct 12 '07 #16

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

Similar topics

2
by: Madhav | last post by:
I have the following statements in my script. ---------------------------------------------------------- textToWrite = "<HTML> \n" + "<HEAD> \n" + "<TITLE>Calendar</TITLE> \n" + "<SCRIPT...
4
by: MPennig | last post by:
Here's my situation. I have a function defined in my document's <head> section which adds a <script> tag to a specified <div> tag. The added <script> has a src="" attribute pointing to a PHP file,...
23
by: Loony | last post by:
I have got a code like this in HTML section in ASP file which includes javascript file! The script works under MS IE but doesn't with Firefox! Can anybody tell me what is wrong? <HTML>...
8
by: Brett Robichaud | last post by:
I understand how code-behind can handle events for a page, but can I call a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script>...
2
by: Jeffrey T. | last post by:
I had some JavaScript functions defined in the <SCRIPT> section at the top of an aspx page (tested fine there). I then moved the JavaScript functions to their own separate file and then...
12
by: Iddo | last post by:
Hi, I am having a strange problem... I have an HTML file which has 2 script tags: 1) <script language="javascript" id="ABC" src="ABC.js" /> 2) <script id="general" language="javascript">...
44
by: rhythmace | last post by:
W3C HTML validator passes this: .... <script type="text/javascript" src="foo.js"> <script type="text/javascript"> ....script in here... </script> ....
2
by: Rolf Welskes | last post by:
Hello, I have simple in one folder FolderA MyMaster.master and script01.js styles01.css The content pages are in
5
by: bob | last post by:
Hi, This code gives two errors, one on each </scripttag: the first: "statement cannot appear in method body" the last: "end of tag has no matching start tag" Any way to solve this? Thanks...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.