Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Do <script tags have to appear in <head section?

Reply
Thread Tools

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

 
 
Stapes
Guest
Posts: n/a
 
      10-11-2007
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

 
Reply With Quote
 
 
 
 
matatunos
Guest
Posts: n/a
 
      10-11-2007
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


 
Reply With Quote
 
 
 
 
Captain Paralytic
Guest
Posts: n/a
 
      10-11-2007
On 11 Oct, 10:40, matatunos <(E-Mail Removed)> wrote:
> 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?

 
Reply With Quote
 
Stapes
Guest
Posts: n/a
 
      10-11-2007
On 11 Oct, 10:40, matatunos <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
matatunos
Guest
Posts: n/a
 
      10-11-2007
>>
>> 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")


 
Reply With Quote
 
riog
Guest
Posts: n/a
 
      10-11-2007
Hi,

see http://www.phpied.com/javascript-include/

1. On your HTML page:

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

2. create includes.js containing:

<script type="text/javascript">
function include_dom(script_filename) {
var html_doc = document.getElementsByTagName('head').item(0);
var js = document.createElement('script');
js.setAttribute('language', 'javascript');
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', script_filename);
html_doc.appendChild(js);
return false;
}

include_dom("js/includes.js");
// add more javascript files here
</script>

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      10-11-2007
On Oct 11, 9:13 pm, riog <(E-Mail Removed)> wrote:
> Hi,
>
> seehttp://www.phpied.com/javascript-include/
>
> 1. On your HTML page:
>
> <script type="text/javascript" src="includes.js"></script>
>
> 2. create includes.js containing:
>
> <script type="text/javascript">
> function include_dom(script_filename) {
> var html_doc = document.getElementsByTagName('head').item(0);
> var js = document.createElement('script');
> js.setAttribute('language', 'javascript');
> js.setAttribute('type', 'text/javascript');
> js.setAttribute('src', script_filename);
> html_doc.appendChild(js);
> return false;
> }
>
> include_dom("js/includes.js");
> // add more javascript files here
> </script>


Why would you bother to use a problematic script to load script files
that could be loaded more reliably using script elements in the source
HTML?

How does the above address the OP's issue of very large pages?


--
Rob

 
Reply With Quote
 
Captain Paralytic
Guest
Posts: n/a
 
      10-11-2007
On 11 Oct, 12:33, RobG <(E-Mail Removed)> wrote:
> 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).

 
Reply With Quote
 
Stapes
Guest
Posts: n/a
 
      10-11-2007
On 11 Oct, 12:13, riog <(E-Mail Removed)> wrote:
> Hi,
>
> seehttp://www.phpied.com/javascript-include/
>
> 1. On your HTML page:
>
> <script type="text/javascript" src="includes.js"></script>
>
> 2. create includes.js containing:
>
> <script type="text/javascript">
> function include_dom(script_filename) {
> var html_doc = document.getElementsByTagName('head').item(0);
> var js = document.createElement('script');
> js.setAttribute('language', 'javascript');
> js.setAttribute('type', 'text/javascript');
> js.setAttribute('src', script_filename);
> html_doc.appendChild(js);
> return false;
> }
>
> include_dom("js/includes.js");
> // add more javascript files here
> </script>


That looks good. How do I add the javascript files where it says //
add more javascript files here ?

i.e. js/dnncore.js

Stapes

 
Reply With Quote
 
Captain Paralytic
Guest
Posts: n/a
 
      10-11-2007
On 11 Oct, 13:10, Stapes <(E-Mail Removed)> wrote:
> On 11 Oct, 12:13, riog <(E-Mail Removed)> wrote:
>
>
>
>
>
> > Hi,

>
> > seehttp://www.phpied.com/javascript-include/

>
> > 1. On your HTML page:

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

>
> > 2. create includes.js containing:

>
> > <script type="text/javascript">
> > function include_dom(script_filename) {
> > var html_doc = document.getElementsByTagName('head').item(0);
> > var js = document.createElement('script');
> > js.setAttribute('language', 'javascript');
> > js.setAttribute('type', 'text/javascript');
> > js.setAttribute('src', script_filename);
> > html_doc.appendChild(js);
> > return false;
> > }

>
> > include_dom("js/includes.js");
> > // add more javascript files here
> > </script>

>
> That looks good. How do I add the javascript files where it says //
> add more javascript files here ?
>
> i.e. js/dnncore.js
>
> Stapes- Hide quoted text -
>
> - Show quoted text -


I would use the keyboard to type:
include_dom("js/dnncore.js");

But if you just do that, you will load all the files as you are doing
using teh script tags and so you have no improvement.

You need to look at the style for http://www.phpied.com/files/jinc/test5.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer Rob Nicholson ASP .Net 3 05-28-2005 03:11 PM
The asp Tags dosn't appear =?Utf-8?B?QWhtZWQgSGF6emFh?= ASP .Net 4 04-26-2005 03:25 PM
Unable to have tags within tags?? Kwasi Java 13 12-01-2004 02:57 PM
RegEx to find CFML tags nested in HTML tags Dean H. Saxe Perl 0 01-03-2004 06:11 PM
Custom Tags within Custom Tags. Ranganath Java 2 10-21-2003 06:14 AM



Advertisments