1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Can I just add "async" to make a script load asynchronously?

Discussion in 'JavaScript' started by asabet, Jan 6, 2015.

  1. #1
    For example, I use Skimlinks on my website, and the code is:

    <script type="text/javascript" src="//s.skimresources.com/js/67963X1515853.skimlinks.js"></script>
    Code (markup):
    Can I just change that to the following to make it load asynchronously, and will it still work to affiliate links?

    <script type="text/javascript" src="//s.skimresources.com/js/67963X1515853.skimlinks.js async"></script>
    Code (markup):
    If so, would the same work for my Amazon CPM ads? For example, I could change this?

    <script type="text/javascript" language="javascript" src="//c.amazon-adsystem.com/aax2/getads.js"></script>
    <script type="text/javascript" language="javascript">
    //<![CDATA[
    aax_getad_mpb({
      "size":"300x250",
      "slot_uuid":"15147327-1f46-48c3-ba92-6a152603cd8b"
    });
    //]]>
    </script>
    Code (markup):
    (adding two instances of "async") to this?

    <script type="text/javascript" language="javascript" src="//c.amazon-adsystem.com/aax2/getads.js" async></script>
    <script type="text/javascript" language="javascript" async>
    //<![CDATA[
    aax_getad_mpb({
      "size":"300x250",
      "slot_uuid":"15147327-1f46-48c3-ba92-6a152603cd8b"
    });
    //]]>
    </script>
    Code (markup):
     
    Solved! View solution.
    asabet, Jan 6, 2015 IP
  2. #2
    You can only use asnyc when you don't depend on that particular script further down in your code. The example you showed won't work, since the first script will get loaded asynchronously, and your code will run immediately after that, which would cause an error, since the first script isn't loaded yet.

    You can only use async for javascript files which are independent.
     
    darthdeus, Jan 24, 2015 IP
  3. asabet

    asabet Active Member

    Messages:
    125
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    90
    #3
    Got it. Thanks!
     
    asabet, Jan 24, 2015 IP