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.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Too many Javascripts per page?

    Thank you for reading my question! We are new to adding javascript to our webpages and we have a question that hopefully someone can help us with. We are using Amazon's MP3 music javascript widget which allows our customer to preview a song and go to Amazon to purchase it if they like.

    So far, we have about 50 of these widgets on our Music Recommendations webpage.

    Our problem is that a few (probably less than 25) of these javascript widgets on a page seem to work fine (all paint properly on the screen). However, when we add more on the page (now up to 50), some widgets randomly don't finish painting and we're left with a blank white box on the screen instead of the functioning widget. Every time we refresh the page, a different random number of the 50 widgets fail. Each of the widgets work on their own when they do paint the screen correctly so we're confident they are coded correctly

    We have tested this on many different web browsers as well as different PCs.

    If I had to guess, I think we must be running into some type of limit on the number of javascripts per page that will function reliably.

    Below is the code that Amazon provides to us for a single javascript widget:

    Code:
    <script type='text/javascript'>
    var amzn_wdgt={widget:'MP3Clips'};
    amzn_wdgt.tag='d99999-20';
    amzn_wdgt.widgetType='ASINList';
    amzn_wdgt.ASIN='B001KVXJPG';
    amzn_wdgt.title='What we\'ve been listening to lately...';
    amzn_wdgt.width='120';
    amzn_wdgt.height='90';
    amzn_wdgt.shuffleTracks='False';
    amzn_wdgt.marketPlace='US';
                </script>
    <script type='text/javascript' src='http://wms.assoc-amazon.com/20070822/US/js/swfobject_1_5.js'>
    </script>
    On our page, we have the code above repeated about 50 times varying one variable that pulls each different song.

    We've been reading and trying to educate ourselves about javascript and want to confirm a few things. Our questions are:

    1. Is this an "External JavaScript" ?

    2. Do different web browsers have limits on the number of simultaneous javascripts running on a page? Execution time or number perhaps?

    3. If there are time limits or simultaneous number limits, is there a way to delay execution of groups of these widgets to get them all to finish?

    4. Should we be coding these a whole different way given the number we using?

    5. Will it just not work in our situation since we can't control Amazon's side of things?

    We really appreciate any comments that will help steer us in the right direction. We have asked Amazon tech support, but they just reply that there are no limits and it should work fine. Somehow, I think that may not be the case.

    Thanks again!
    Last edited by vinyl-junkie; 08-10-2013 at 01:40 PM. Reason: Corrected code tags

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,592
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by music25 View Post
    1. Is this an "External JavaScript" ?
    http://wms.assoc-amazon.com/20070822...fobject_1_5.js is an external JavaScript - the rest of the code is inline JavaScript

    Quote Originally Posted by music25 View Post
    2. Do different web browsers have limits on the number of simultaneous javascripts running on a page? Execution time or number perhaps?
    No - they all single thread JavaScript so only one statement runs at a time.

    Quote Originally Posted by music25 View Post
    4. Should we be coding these a whole different way given the number we using?
    Yes - but you'd need to update the code in the http://wms.assoc-amazon.com/20070822...fobject_1_5.js to get rid of the obsolete calls to document.write and to only define the functions in the code once for your page instead of redefining them 50+ times with the exact same code. Their code as written is intended to appear once only per page.
    Last edited by felgall; 08-10-2013 at 11:13 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.

  • Users who have thanked felgall for this post:

    music25 (08-11-2013)

  • #3
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Stephen (felgall),

    Thank you very much for your reply and information! It has definitely helped us understand and decide how to proceed with the development of our page. Have a great day!

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,277
    Thanks
    10
    Thanked 581 Times in 562 Posts
    Quote Originally Posted by music25 View Post
    2. Do different web browsers have limits on the number of simultaneous javascripts running on a page? Execution time or number perhaps?

    3. If there are time limits or simultaneous number limits, is there a way to delay execution of groups of these widgets to get them all to finish?
    most browsers seem to complain if the UI locks for 5 seconds or more from any single script, or during loading. a slight delay can allow you to run another 4.5 seconds of script without complain from the browser.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • Users who have thanked rnd me for this post:

    music25 (08-12-2013)


  •  

    Posting Permissions

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