Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 7 of 8 FirstFirst ... 5678 LastLast
Results 91 to 105 of 106
  1. #91
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by felgall View Post
    JavaScript files are a special case - they can normally only single thread for download unless you specify an async or defer attribute in the script tag and the browser recognises that attribute OR you add the script tags dynamically from JavaScript.
    Just have a look at your browser's network tab, will you? All current major browsers except Opera download several Javascript files simultaneously, regardless of any defer or async attributes.


    Quote Originally Posted by felgall View Post
    Modern browsers only download multiple JavaScripts simultaneously if you specify a defer or async attribute on the script tag - without that attribute they revert to single threading the JavaScript just in case there is a document.write statement that requires single threading the script.
    You're mixing up two different concepts here: defer and async are about when a piece of Javascript is executed, not when and how it's loaded. The time at which it's being executed obviously has an effect on the rendering timing, but we're talking about how scripts are loaded here, and that's completely at the browser's discretion — and with modern browsers it's multiple scripts at a time.


    Quote Originally Posted by felgall View Post
    Downloading eight files at a time (or however many a particular browser allows) will always better utilize your available bandwidth than downloading them one at a time.
    That's true, but it's not the point — no one suggested that loading script files one at the time (which modern browsers won't do anyway) makes any sense. The point is that with increasing bandwidths and constant network latencies downloading one single script file is faster than downloading smaller chunks eight at a time.


    Quote Originally Posted by felgall View Post
    Also I think you have your calculation wrong regarding the download time for a 200k script. I did a rough calculation and worked out that if it fully utilised the download bandwidth of my internet connection (which is about 5Mb) then it would take about 430ms for the file to download
    I specified the assumptions on the network connection I used to calculate those values, and obviously you'll get different values with different assumptions. I think you don't actually understand how to calculate total download time, though, since you're only talking about your bandwidth and not about network latency, which, as I have pointed out several times now, is becoming the most important factor in page load times. That's the whole reason we're talking about reducing the number of HTTP-requests by combining Javascript files.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  2. #92
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    You lot are endlessly readable. I love it! And learning...

    But why not provide a few demo pages where you prove what you are asking us all to believe?

    It's like listening to a bunch of horsetrainers with stopwatches before the big race.

    Why not show us what you believe to be true?

    I'm sorry to say this, but having provided dozens of demo pages in my time (which I have for nearly 10 years continued to provide online as links from this website), I think the main protagonists in this argument are a tad lazy just to proffer information without proof.

    Javascript can show timings to the nanosecond (?) right?

    Are you up for it?
    Last edited by tpeck; 04-03-2012 at 01:56 PM.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  3. #93
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by tpeck View Post
    But why not provide a few demo pages where you prove what you are asking us all to believe?
    There isn't much to demo here (Javascript can measure its execution time but not its load time — this has to be done by the browser or external tools). You can just browse to an arbitrary page with the network tab of your browser's dev tools open, though, and see for yourself how script files are being loaded and what amount of time is used for server roundtrips.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  4. #94
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    884
    Thanks
    53
    Thanked 6 Times in 5 Posts
    So we have to provide the demos.

    Mmm. Sorry I think Blaze4218 and Philip M. answered the question on page 1 and the rest is just argument. Interesting, but point scoring only.
    The difference between genius and stupidity is that genius has its limits. (Albert Einstein)

  5. The Following 2 Users Say Thank You to tpeck For This Useful Post:

    blaze4218 (04-03-2012), Philip M (04-03-2012)

  6. #95
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,313
    Thanks
    203
    Thanked 2,564 Times in 2,542 Posts
    My book which is entitled "The Meaningless Of Nothing" (500pp) will be published soon.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  7. #96
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    Quote Originally Posted by tpeck View Post
    Interesting, but point scoring only.
    But what a fun ride it's been
    Allwisend bin ich nicht, doch viel ist mir bewursst
    -Goethe

  8. #97
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by tpeck View Post
    So we have to provide the demos.
    If you're really interested, yes. Since browsers are smarter now, the days of huge page load improvements by combining scripts or loading them asynchronously are gone, and I'm not out there to convince anyone to use any specific method.

    That number game aside, I mainly got involved to correct a few things that were unambiguously wrong; maybe it helps someone to summarize a few points that came up:

    • A gain in downloading efficiency is a different thing than a gain in code efficiency.
    • Modern browsers do not insist on downloading only one Javascript file at a time. There's still a limit, though.
    • The defer and async properties are not about how and when scripts are downloaded, but about when they are executed, and when the page is rendered.
    • If one method is definitely better than the others in the current browser scope, maintainability should not come into play, because it's done for production only and is easily automated.
    • Network latency can't improve much over time because of physical restrictions, whereas bandwidths will. In 10 years' time, it might be better to serve an entire website including images in one single file, than to force several requests.
    Last edited by venegal; 04-03-2012 at 06:07 PM.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  9. #98
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by venegal View Post
    I specified the assumptions on the network connection I used to calculate those values, and obviously you'll get different values with different assumptions. I think you don't actually understand how to calculate total download time, though, since you're only talking about your bandwidth and not about network latency, which, as I have pointed out several times now, is becoming the most important factor in page load times. That's the whole reason we're talking about reducing the number of HTTP-requests by combining Javascript files.
    I was only calculating the actual minimum time required to download the 200k file on a connection 5 times the speed of the one you assumed and got a much higher figure just for that than you did for your entire calculation. Add in the latency to the figure I had and your figures would be too small by a factor of 10 or more. Perhaps you were assuming the connection speed was in bytes rather than bits.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  10. #99
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Oh, I see. Yes, I did write 1MB/s, and not the equivalent Mb/s speed, so the calculations would be easier to follow.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  11. #100
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by venegal View Post
    Just have a look at your browser's network tab, will you? All current major browsers except Opera download several Javascript files simultaneously, regardless of any defer or async attributes.
    Okay I have checked out the network tab in several different browsers.

    Opera can download 16 files from one site simultaneously (unless I change that value to something bigger).

    Chrome appears to be sharing settings with IE and IE doesn't identify the number of connections it allows (at least not anywhere I can find)

    Firefox also has no information on the number of connections allowed on the network tab.

    Safari doesn't even appear to have a network tab.

    Regardless of whether I can find that information though or not those limits have always applied to all file types except JavaScript since downloading scripts in parallel can easily break their functionality if one depends on the other.


    I have also done a search of the internet and have not been able to locate any page that indicates that recent browsers have been modified to break web pages that rely on scripts downloading sequentially by downloading them in parallel.

    A simple example would clearly demonstrate how simultaneous downloading would break scripts. You just need two script calls - one to load jQuery and the second with a script that uses it. Assuming the computer doesn't already have a cached copy of jQuery that file would take far longer to download than the other JavaScript file and so the script that intends to use jQuery would download and attempt to run long before jQuery itself has finished downloading.


    If one or more modern browsers now do allow scripts to download in parallel can you please provide a link to a web page that explains the change.
    Last edited by felgall; 04-03-2012 at 09:23 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  12. #101
    Regular Coder
    Join Date
    Apr 2005
    Location
    Texas
    Posts
    448
    Thanks
    24
    Thanked 63 Times in 63 Posts
    http://developer.yahoo.com/performance/rules.html
    The problem caused by scripts is that they block parallel downloads. The HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames.
    I don't know how old or accurate this information is. But it was the original reason I first migrated my scripts out of my head...
    Allwisend bin ich nicht, doch viel ist mir bewursst
    -Goethe

  13. #102
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by felgall View Post
    Okay I have checked out the network tab in several different browsers.
    Sorry, I should have clarified (or maybe I did somewhere? This thread is getting long!): I don't mean the network tab in the browser preferences but in the browser's built-in development tools (or Firebug). There you can see for yourself for each page you're visiting how all the files are being loaded. This will look something like the two graphics here http://www.artzstudio.com/2008/07/be...ynchronous-js/, with modern browsers looking more like the second one.


    Quote Originally Posted by felgall View Post
    Regardless of whether I can find that information though or not those limits have always applied to all file types except JavaScript since downloading scripts in parallel can easily break their functionality if one depends on the other.
    Parallel downloading would break dependencies if the scripts were executed as soon as they are loaded, but that's not the case — just because scripts are downloaded simultaneously doesn't mean modern browsers aren't smart enough to still execute them in order. Page rendering will be blocked, though.

    Quote Originally Posted by felgall View Post
    If one or more modern browsers now do allow scripts to download in parallel can you please provide a link to a web page that explains the change.
    I don't have any good links at hand — I'm solely relying on what the browsers' network tools are telling me here. If they are lying to me, then I'm wrong, but I don't have a reason to believe that. Since that change isn't breaking anything (apart, maybe, from optimizations implemented against some non-standardized behaviour) or adding any cool new functionality, it might not have been worth communicating it clearly.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  14. #103
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by blaze4218 View Post
    http://developer.yahoo.com/performance/rules.html
    I don't know how old or accurate this information is. But it was the original reason I first migrated my scripts out of my head...
    The Wayback Machine tells me it's from 2007, and it's a pity there isn't some sort of vendor-controlled best practices living standard. Scripts out of the head still seems feasible for rendering blocking reasons, but there's sadly no easy way of knowing whether (or when) future browser implementations will nullify those efforts by some other sort of trickery.
    .My new Javascript tutorial site: http://reallifejs.com/
    .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
    .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

  15. #104
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    [QUOTE=venegal;1211889I'm solely relying on what the browsers' network tools are telling me here. [/QUOTE]

    Okay, I found the network tools you are referring to and ran tests in Opera, Google Chrome and Internet Explorer.

    From the results shown there you are right - the browsers now don't insist on single threading JavaScript and can download them in parallel. Your specifying Opera as an exception was wrong because it behaved the same as the others.

    So that makes my argument for splitting your JavaScript into several files even stronger since you don't even need to add the script tags from JavaScript in order to do parallel downloads. You can achieve it just by specifying several script tags one after the other.

    The results on that network tab clearly showed six scripts downloading in parallel taking scarcely longer than just one of those scripts by itself would have taken - and that is taking everything into account since what shows on that tab is the actual live demo that someone asked for earlier in the thread.

    This change to the way that browsers download JavaScript makes it even easier to speed up the downloading of JavaScript by splitting it into several separate files.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  16. #105
    New Coder
    Join Date
    Aug 2012
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I don't think anyone here is mocking another's lack of language at all, but one gets quickly tired of a lack of consideration for the viewers having to wade through punctuation salad when we should all be taking pains to be as painstaking as we can.


 
Page 7 of 8 FirstFirst ... 5678 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •