Can we use async attribute for script loaded dynamically?












0















Can we use async attribute to load script asynchronously for script loaded dynamically?










share|improve this question

























  • Can you elaborate a bit more on what you mean by script loaded dynamically?

    – Dinesh Pandiyan
    Nov 24 '18 at 6:08











  • Yes.Will “Async” attribute loads script asynchronously when used for a script that is dynamically added to the DOM

    – user3190467
    Nov 24 '18 at 6:11











  • Possible duplicate of Is the "async" attribute/property useful if a script is dynamically added to the DOM?

    – Dinesh Pandiyan
    Nov 24 '18 at 6:19
















0















Can we use async attribute to load script asynchronously for script loaded dynamically?










share|improve this question

























  • Can you elaborate a bit more on what you mean by script loaded dynamically?

    – Dinesh Pandiyan
    Nov 24 '18 at 6:08











  • Yes.Will “Async” attribute loads script asynchronously when used for a script that is dynamically added to the DOM

    – user3190467
    Nov 24 '18 at 6:11











  • Possible duplicate of Is the "async" attribute/property useful if a script is dynamically added to the DOM?

    – Dinesh Pandiyan
    Nov 24 '18 at 6:19














0












0








0








Can we use async attribute to load script asynchronously for script loaded dynamically?










share|improve this question
















Can we use async attribute to load script asynchronously for script loaded dynamically?







html5 css3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 11:07









Roman Pokrovskij

4,323125081




4,323125081










asked Nov 24 '18 at 5:56









user3190467user3190467

43




43













  • Can you elaborate a bit more on what you mean by script loaded dynamically?

    – Dinesh Pandiyan
    Nov 24 '18 at 6:08











  • Yes.Will “Async” attribute loads script asynchronously when used for a script that is dynamically added to the DOM

    – user3190467
    Nov 24 '18 at 6:11











  • Possible duplicate of Is the "async" attribute/property useful if a script is dynamically added to the DOM?

    – Dinesh Pandiyan
    Nov 24 '18 at 6:19



















  • Can you elaborate a bit more on what you mean by script loaded dynamically?

    – Dinesh Pandiyan
    Nov 24 '18 at 6:08











  • Yes.Will “Async” attribute loads script asynchronously when used for a script that is dynamically added to the DOM

    – user3190467
    Nov 24 '18 at 6:11











  • Possible duplicate of Is the "async" attribute/property useful if a script is dynamically added to the DOM?

    – Dinesh Pandiyan
    Nov 24 '18 at 6:19

















Can you elaborate a bit more on what you mean by script loaded dynamically?

– Dinesh Pandiyan
Nov 24 '18 at 6:08





Can you elaborate a bit more on what you mean by script loaded dynamically?

– Dinesh Pandiyan
Nov 24 '18 at 6:08













Yes.Will “Async” attribute loads script asynchronously when used for a script that is dynamically added to the DOM

– user3190467
Nov 24 '18 at 6:11





Yes.Will “Async” attribute loads script asynchronously when used for a script that is dynamically added to the DOM

– user3190467
Nov 24 '18 at 6:11













Possible duplicate of Is the "async" attribute/property useful if a script is dynamically added to the DOM?

– Dinesh Pandiyan
Nov 24 '18 at 6:19





Possible duplicate of Is the "async" attribute/property useful if a script is dynamically added to the DOM?

– Dinesh Pandiyan
Nov 24 '18 at 6:19












2 Answers
2






active

oldest

votes


















0














By script loaded dynamically, if you mean adding javascript code dynamically to your page, then the answer is No.



async attribute can only be used on loading external scripts that are referred to via a URL specified in src attribute.




The async attribute is only for external scripts (and should only be used if the src attribute is present)




Example, You can load only scripts like this asyncronously



 <script src="external-file.js" async></script> 





share|improve this answer































    0














    It is an interesting point.



    Here is an example, some Similar StackOverflow questions, and jQuery Document link For use of Async attribute



    Example:



    <!DOCTYPE html>
    <html>

    <head>
    <title>Async Test Attribute</title>
    </head>

    <body>
    <script src="async_demo.js" async></script>
    <h2>Welcome to Demo!</h2>
    <script>
    console.log('HELLO NON-async');
    </script>
    </body>

    </html>


    async_demo.js



    console.log('HELLO Async');


    Screencast for above code: https://hareen-nipl.tinytake.com/sf/MzEwNzYzOV85MzEzNTgz



    Async jQuery : http://forum.jquery.com/topic/jquery-ajax-async-vs-html5-script-async



    W3School Document: https://www.w3schools.com/tags/att_script_async.asp



    Similar StackOverflow questions




    1. Add defer or async attribute to dynamically generated script tags via javascript


    2. Is the "async" attribute/property useful if a script is dynamically added to the DOM?



    Please comment down below if you have any questions for the same.






    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455565%2fcan-we-use-async-attribute-for-script-loaded-dynamically%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      By script loaded dynamically, if you mean adding javascript code dynamically to your page, then the answer is No.



      async attribute can only be used on loading external scripts that are referred to via a URL specified in src attribute.




      The async attribute is only for external scripts (and should only be used if the src attribute is present)




      Example, You can load only scripts like this asyncronously



       <script src="external-file.js" async></script> 





      share|improve this answer




























        0














        By script loaded dynamically, if you mean adding javascript code dynamically to your page, then the answer is No.



        async attribute can only be used on loading external scripts that are referred to via a URL specified in src attribute.




        The async attribute is only for external scripts (and should only be used if the src attribute is present)




        Example, You can load only scripts like this asyncronously



         <script src="external-file.js" async></script> 





        share|improve this answer


























          0












          0








          0







          By script loaded dynamically, if you mean adding javascript code dynamically to your page, then the answer is No.



          async attribute can only be used on loading external scripts that are referred to via a URL specified in src attribute.




          The async attribute is only for external scripts (and should only be used if the src attribute is present)




          Example, You can load only scripts like this asyncronously



           <script src="external-file.js" async></script> 





          share|improve this answer













          By script loaded dynamically, if you mean adding javascript code dynamically to your page, then the answer is No.



          async attribute can only be used on loading external scripts that are referred to via a URL specified in src attribute.




          The async attribute is only for external scripts (and should only be used if the src attribute is present)




          Example, You can load only scripts like this asyncronously



           <script src="external-file.js" async></script> 






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 6:16









          Dinesh PandiyanDinesh Pandiyan

          2,5981926




          2,5981926

























              0














              It is an interesting point.



              Here is an example, some Similar StackOverflow questions, and jQuery Document link For use of Async attribute



              Example:



              <!DOCTYPE html>
              <html>

              <head>
              <title>Async Test Attribute</title>
              </head>

              <body>
              <script src="async_demo.js" async></script>
              <h2>Welcome to Demo!</h2>
              <script>
              console.log('HELLO NON-async');
              </script>
              </body>

              </html>


              async_demo.js



              console.log('HELLO Async');


              Screencast for above code: https://hareen-nipl.tinytake.com/sf/MzEwNzYzOV85MzEzNTgz



              Async jQuery : http://forum.jquery.com/topic/jquery-ajax-async-vs-html5-script-async



              W3School Document: https://www.w3schools.com/tags/att_script_async.asp



              Similar StackOverflow questions




              1. Add defer or async attribute to dynamically generated script tags via javascript


              2. Is the "async" attribute/property useful if a script is dynamically added to the DOM?



              Please comment down below if you have any questions for the same.






              share|improve this answer






























                0














                It is an interesting point.



                Here is an example, some Similar StackOverflow questions, and jQuery Document link For use of Async attribute



                Example:



                <!DOCTYPE html>
                <html>

                <head>
                <title>Async Test Attribute</title>
                </head>

                <body>
                <script src="async_demo.js" async></script>
                <h2>Welcome to Demo!</h2>
                <script>
                console.log('HELLO NON-async');
                </script>
                </body>

                </html>


                async_demo.js



                console.log('HELLO Async');


                Screencast for above code: https://hareen-nipl.tinytake.com/sf/MzEwNzYzOV85MzEzNTgz



                Async jQuery : http://forum.jquery.com/topic/jquery-ajax-async-vs-html5-script-async



                W3School Document: https://www.w3schools.com/tags/att_script_async.asp



                Similar StackOverflow questions




                1. Add defer or async attribute to dynamically generated script tags via javascript


                2. Is the "async" attribute/property useful if a script is dynamically added to the DOM?



                Please comment down below if you have any questions for the same.






                share|improve this answer




























                  0












                  0








                  0







                  It is an interesting point.



                  Here is an example, some Similar StackOverflow questions, and jQuery Document link For use of Async attribute



                  Example:



                  <!DOCTYPE html>
                  <html>

                  <head>
                  <title>Async Test Attribute</title>
                  </head>

                  <body>
                  <script src="async_demo.js" async></script>
                  <h2>Welcome to Demo!</h2>
                  <script>
                  console.log('HELLO NON-async');
                  </script>
                  </body>

                  </html>


                  async_demo.js



                  console.log('HELLO Async');


                  Screencast for above code: https://hareen-nipl.tinytake.com/sf/MzEwNzYzOV85MzEzNTgz



                  Async jQuery : http://forum.jquery.com/topic/jquery-ajax-async-vs-html5-script-async



                  W3School Document: https://www.w3schools.com/tags/att_script_async.asp



                  Similar StackOverflow questions




                  1. Add defer or async attribute to dynamically generated script tags via javascript


                  2. Is the "async" attribute/property useful if a script is dynamically added to the DOM?



                  Please comment down below if you have any questions for the same.






                  share|improve this answer















                  It is an interesting point.



                  Here is an example, some Similar StackOverflow questions, and jQuery Document link For use of Async attribute



                  Example:



                  <!DOCTYPE html>
                  <html>

                  <head>
                  <title>Async Test Attribute</title>
                  </head>

                  <body>
                  <script src="async_demo.js" async></script>
                  <h2>Welcome to Demo!</h2>
                  <script>
                  console.log('HELLO NON-async');
                  </script>
                  </body>

                  </html>


                  async_demo.js



                  console.log('HELLO Async');


                  Screencast for above code: https://hareen-nipl.tinytake.com/sf/MzEwNzYzOV85MzEzNTgz



                  Async jQuery : http://forum.jquery.com/topic/jquery-ajax-async-vs-html5-script-async



                  W3School Document: https://www.w3schools.com/tags/att_script_async.asp



                  Similar StackOverflow questions




                  1. Add defer or async attribute to dynamically generated script tags via javascript


                  2. Is the "async" attribute/property useful if a script is dynamically added to the DOM?



                  Please comment down below if you have any questions for the same.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 24 '18 at 6:36

























                  answered Nov 24 '18 at 6:30









                  HareenHareen

                  263




                  263






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455565%2fcan-we-use-async-attribute-for-script-loaded-dynamically%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Futebolista

                      Feedback on college project

                      Albești (Vaslui)