Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
815 views
in Q2A Core by

How can I make asnyc all js?

<script src="../qa-content/jquery-1.7.2.min.js" type="text/javascript" asnyc ></script>
<script src="../qa-content/qa-page.js" type="text/javascript" asnyc ></script>
<script src="../qa-content/qa-question.js" type="text/javascript" asnyc ></script>
 
etc...
 

2 Answers

0 votes
by

You shouldn't change those files to async because then the JS will break. Using async means the files will download and execute in any order. You don't want stuff depending on jQuery executing before jQuery is available.

Potentially you could use "defer" instead, which delays execution until the page is ready and executes them in order. The problem here is that either everything or nothing must be deferred. If only some things are deferred, anything not deferred (e.g. a script from a plugin) could break.

If you still decide to change the JS, currently those files are set up in the core - see the qa_output_content function in qa-page.php. The better (but more difficult) way is to override the head_script function in your theme, detect when a line is a script file, and do some string/regex replacement.

0 votes
by

It is easy to add async attribute, but I will recommend that you do not do it.

Reasons:

  1. Q2A have not yet officially support HTML5 except some themes (e.g. my FlexArmor1/2).
  2. Since scripts with async attribute are not guaranteed execution order. Therefore, you can not use async attribute in dependence of scripts such as your example. If you use this attribute in completely independent script, might be a little performance increases. However, before this, it would be first to move script lines to the bottom of HTML.
...