By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Separate file vs. embedded "javascript:" - how fast is the page load?

P: n/a
Hi,
which is better approach to store my JavaScript code, to store it in
separate .js file
or to embed the code within HTML attributes (e.g. <p
onclick="javascript:submit();">click this</p>)?
I am interested in performance, i.e. how quick is page loaded in each case?

I think the better one is to store the code in separate .js file so that the
user browser can cache the file
(source: http://www.quirksmode.org/js/placejs.html#link1) but I am not
entirely sure.

Thanks in advance.

--
Slavo Smutny
Nov 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Slavo Smutny wrote on 21 nov 2005 in comp.lang.javascript:
Hi,
which is better approach to store my JavaScript code, to store it in
separate .js file
or to embed the code within HTML attributes (e.g. <p
onclick="javascript:submit();">click this</p>)?
onclick="javascript:submit();"

is always wrong because superfluous, use:

onclick='submit();'

You cannot put the above in a .js file however.

perhaps you mean: <script ..></script> ?
I am interested in performance, i.e. how quick is page loaded in each
case?
Did you test it?
I think the better one is to store the code in separate .js file so
that the user browser can cache the file
(source: http://www.quirksmode.org/js/placejs.html#link1) but I am not
entirely sure.


The catching is true, but "better" depends on the file-size, the importance
of loading time, and the effect on server use amount.

In general the first reason to have a .js file is using that same file for
multiple pages, IMHO, with many advantages, like the ones above, but also
disadvantages, like extensive testing when you change the file.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Nov 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.