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

HTML download efficiency

I am curious to know if any research has been conducted regarding the
efficiency of having a single (large) .js file downloaded for a
webpage compared to several smaller .js files.

For example in my web pages I often include the scripting code
<script language="javascript" type="text/javascript"
src="ascript.js"></script>

which contains all the code for a given function, i.e. the main
function and any subsidiary functions.
I have developed a few library functions (leftString, rightString,
etc.) and these can be invoked by functions in other .js files, so I
would have something like
<script language="javascript" ... src="libs.js"></script>
<script language="javascript" ... src="ascript.js"></script>

I'm just wondering if there is any difference in download time when
the HTML has to download these separate .js files rather than a single
one.

Even though the use of broadband is spreading I still like to keep my
web pages as efficient as possible, not everyone has broadband after
all, some still use dial-up connections.

Does anybody know?

Jul 9 '07 #1
3 1416
Gargoyle <no****@loadsarubbish.perswrote:
I'm just wondering if there is any difference in download time when
the HTML has to download these separate .js files rather than a single
one.

Even though the use of broadband is spreading I still like to keep my
web pages as efficient as possible, not everyone has broadband after
all, some still use dial-up connections.

Does anybody know?
If you have a lot of small js files then each one will require a separate
request. On a slow link the overhead associated with each request may
become significant.

On the other hand, if you need to change one of your js files then any
browser which has your page in cache will be able to serve up the
unmodified scripts from cache and only the edited one needs to be
downloaded. So if you have a file or files which change frequently load it
separately.

Also, imagine page A requires files W, X and Y and page B needs X, Y and Z:

If you combine each page's javascript then A gets WXY and B gets XYZ which
would be two separate large javascript files. Or you could combine all
possible Javascript for your site and the first page gets the even larger
WXYZ but the second page hit gets it from cache. That way the people who
hit only one page on your site lose out, but if they hit both pages they
gain. Or you could combine XY and keep W and Z separate but then you have a
maintenance headache constantly tuning your site every time a page's
requirements change.

In other words there is no simple answer. Use a tool such as Firebug or
Fiddler to see what your pages are actually doing.
Jul 9 '07 #2
On 9 Jul 2007 12:42:38 GMT, Duncan Booth
<du**********@invalid.invalidwrote:
>Gargoyle <no****@loadsarubbish.perswrote:
>I'm just wondering if there is any difference in download time when
the HTML has to download these separate .js files rather than a single
one.

Even though the use of broadband is spreading I still like to keep my
web pages as efficient as possible, not everyone has broadband after
all, some still use dial-up connections.

Does anybody know?

If you have a lot of small js files then each one will require a separate
request. On a slow link the overhead associated with each request may
become significant.

On the other hand, if you need to change one of your js files then any
browser which has your page in cache will be able to serve up the
unmodified scripts from cache and only the edited one needs to be
downloaded. So if you have a file or files which change frequently load it
separately.

Also, imagine page A requires files W, X and Y and page B needs X, Y and Z:

If you combine each page's javascript then A gets WXY and B gets XYZ which
would be two separate large javascript files. Or you could combine all
possible Javascript for your site and the first page gets the even larger
WXYZ but the second page hit gets it from cache. That way the people who
hit only one page on your site lose out, but if they hit both pages they
gain. Or you could combine XY and keep W and Z separate but then you have a
maintenance headache constantly tuning your site every time a page's
requirements change.

In other words there is no simple answer. Use a tool such as Firebug or
Fiddler to see what your pages are actually doing.
Thanks for the info Duncan.

In the meantime I've done a few crude tests downloading a page with
three scripts over a DUN connection. I thought one of my script files
was fairly large and yet it only took 2 seconds to download. I guess 2
seconds is reasonable. With a bit of tinkering I could probably get it
down to 1 second.
Jul 9 '07 #3
Gargoyle wrote:
On 9 Jul 2007 12:42:38 GMT, Duncan Booth
<du**********@invalid.invalidwrote:
>Gargoyle <no****@loadsarubbish.perswrote:
>>I'm just wondering if there is any difference in download time when
the HTML has to download these separate .js files rather than a single
one.

Even though the use of broadband is spreading I still like to keep my
web pages as efficient as possible, not everyone has broadband after
all, some still use dial-up connections.

Does anybody know?
If you have a lot of small js files then each one will require a separate
request. On a slow link the overhead associated with each request may
become significant.

On the other hand, if you need to change one of your js files then any
browser which has your page in cache will be able to serve up the
unmodified scripts from cache and only the edited one needs to be
downloaded. So if you have a file or files which change frequently load it
separately.

Also, imagine page A requires files W, X and Y and page B needs X, Y and Z:

If you combine each page's javascript then A gets WXY and B gets XYZ which
would be two separate large javascript files. Or you could combine all
possible Javascript for your site and the first page gets the even larger
WXYZ but the second page hit gets it from cache. That way the people who
hit only one page on your site lose out, but if they hit both pages they
gain. Or you could combine XY and keep W and Z separate but then you have a
maintenance headache constantly tuning your site every time a page's
requirements change.

In other words there is no simple answer. Use a tool such as Firebug or
Fiddler to see what your pages are actually doing.

Thanks for the info Duncan.

In the meantime I've done a few crude tests downloading a page with
three scripts over a DUN connection. I thought one of my script files
was fairly large and yet it only took 2 seconds to download. I guess 2
seconds is reasonable. With a bit of tinkering I could probably get it
down to 1 second.
Strip out the unnecessary comments, (keep them in a source file
elsewhere) and make EVERYTHING that is used twice, a function....

Size is all that really matters with download speed, above a few hundred
ms anyway.
Jul 9 '07 #4

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

Similar topics

1
by: Peter Williams | last post by:
Hello All, I'm a newbie to this ng. I'm posting here because I have a question about debugging some javascript on some pages of my website. Please don't call me a "troll" -- because I'm not one....
59
by: Lennart Björk | last post by:
Hi All, I have a tiny program: <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>MyTitle</title> <meta...
0
by: comp.lang.php | last post by:
I have a form that when you click the "Generate Report" submit button, it will force download a CSV file, required for this project. On the very same page you also have a "Search" submit button,...
335
by: extrudedaluminiu | last post by:
Hi, Is there any group in the manner of the C++ Boost group that works on the evolution of the C language? Or is there any group that performs an equivalent function? Thanks, -vs
1
by: Brett Kelly | last post by:
Ok, I know this sounds odd. Let me explain further. I have an ASP.net page (w/ C# code behind) that, when given a session variable containing the path to a local file, will attempt to start the...
3
by: Chuck Renner | last post by:
Please help! This MIGHT even be a bug in PHP! I'll provide version numbers and site specific information (browser, OS, and kernel versions) if others cannot reproduce this problem. I'm...
8
by: rn5a | last post by:
I have a HTML page named Index.html which is divided into 3 frames. The URL of 2 of the frames are HTML pages but the 3rd frame houses a ASP page. Now when I go to Windows Explorer, navigate to...
3
Chrisjc
by: Chrisjc | last post by:
I was told the other day that I was able to place HTML in my database.. So I thought to my self that be grate for my feature points so I can use bullets... so I put the following code in one of my...
9
by: OldBirdman | last post by:
Efficiency I've never stumbled on any discussion of efficiency of various methods of coding, although I have found posts on various forums where individuals were concerned with efficiency. I'm...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.