473,386 Members | 1,812 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,386 software developers and data experts.

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

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
1 2382
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rick | last post by:
Hi.. I've got some code I wrote in PHP that will generate an HTML page with embedded javascript which in turn creates a new argument string for the browser, but the xhtml parser in Firefox and...
9
by: David D. | last post by:
Does the file extension matter when including a JavaScript file in an HTML page? Normally, one would include a JavaScript file in an HTML page using <script src="foo.JS" type="text/javascript">...
2
by: Robert Oschler | last post by:
I have a web page that has portions of it created by Javascript during the document load, through the use of "document.write()" statements. I can get the contents of the document via the...
7
by: RFS666 | last post by:
Hello, I would like to use variables with a type in jscript.NET. I declare them as follows: var x : double = 5.03; This doesn't work in my script, that I write to the page in codebehind with...
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...
6
by: kelvlam | last post by:
Hello, I'm a new begininer with JavaScript. I'm trying to figure out which is the best approach, and to understand the differences between them. I have a <Aelement that's suppose to either...
26
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are...
19
by: maya | last post by:
hi, so what is "modern" javascript?? the same as "DOM-scripting"? i.e., editing content (or changing appearance of content) dynamically by massaging javascript objects, html elements, etc? ...
1
by: humtum | last post by:
Greetings Everyone! I am working on a Java application where I have to develop a Swings client which talks to a web-server. The client sends the HTTP get request for a specific resource which it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.