Answers.Body: <p>As of Craft 3 (Tested using <a href="https://github.com/craftcms/cms/releases/tag/3.0.0-RC5" rel="noreferrer">RC5</a>) you can do it like this: </p>
  
  <pre><code>{% do view.registerJsFile("path/to/script.js", {"async":"async", "defer":"defer"}) %}
  </code></pre>
  
  <p>Source: <a href="http://www.yiiframework.com/doc-2.0/yii-web-view.html#registerJsFile()-detail" rel="noreferrer">Documentation for Yii's view.registerJsFile()</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-15T16:47:12.310Z
Answers.LastActivityDate: 2018-01-15T16:47:12.310Z
Answers.UserDisplayName: stojda
Answers.Body: <p>Knowing that <code>&lt;script&gt;</code>s are imploded with <a href="https://github.com/craftcms/cms/blob/2.6.2986/src/services/TemplatesService.php#L760" rel="nofollow noreferrer">\n</a> char. You can add async defer this way:</p>
  
  <pre><code>{%- set scripts = getFootHtml() | split("\n")  -%}
  {%- for script in scripts -%}
      {%- if script matches "%\/assets\/js\/main\.js%" or ' src=' not in script -%}
          {{- script | raw -}}
      {%- else -%}
          {{- script | replace('script type', 'script async defer type') | raw -}}
      {%- endif -%}
  {%- endfor -%}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-07T14:42:05.887Z
Answers.LastActivityDate: 2017-07-07T14:42:05.887Z
Answers.UserDisplayName: Krzysztof Boduch
Answers.Body: <p>Not as of <a href="https://craftcms.com/changelog#build2791" rel="nofollow">Craft 2.6.2791</a>.</p>
  
  <p>If that's a requirement for you, you can not use that tag and put a block in your footer and manually create the script tag with <code>async defer</code> set.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-19T12:40:24.617Z
Answers.Text: thanks for the feedback Brad - i'll look in to an alternative way of implementing it.
Answers.UserDisplayName: alexr
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-23T16:21:55.757Z
Answers.Text: @alexr how did you implement this in the end? I am currently at the same conundrum.
Answers.UserDisplayName: Terry Upton
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-26T15:17:31.107Z
Answers.Text: @TerryUpton i think in the end i ended up manually putting it in the footer of my site in an if statement. In this particular site I was setting a title var in each template in twig anyway, and only had a map on one page, so i ended up doing something like {% if title == 'mappage' %}<script src="path/to/script" async defer></script>{% endif %}
Answers.UserDisplayName: alexr
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-16T18:44:20.210Z
Answers.LastActivityDate: 2016-06-16T18:44:20.210Z
Answers.UserDisplayName: Brad Bell
Body: <p>Is there a way to set <code>async defer</code> on a <code>&lt;script&gt;</code> tag with the built in: </p>
  
  <pre><code>{% includeJsFile %}
  </code></pre>
  
  <p>It's for Google Maps e.g.: </p>
  
  <pre><code>&lt;script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;callback=initMap"
  async defer&gt;&lt;/script&gt;
  </code></pre>
  
  <p>I'd still like to be able to output this at the bottom of the layout from within another template. Is this possible?</p>
  
Tags: <includejs>
Title: Can you set async defer when using {% includeJsFile %}?
ThreadText: # Can you set async defer when using {% includeJsFile %}?
  
  (Asked by: username_0 on 2016-06-16)
  
  Is there a way to set `async defer` on a `<script>` tag with the built in:
  
  ```
  {% includeJsFile %}
  
  ```
  
  It's for Google Maps e.g.:
  
  ```
  <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"
  async defer></script>
  
  ```
  
  I'd still like to be able to output this at the bottom of the layout from within another template. Is this possible?
  
  **Tags:** includejs
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_3 on 2016-06-16. Score: 4 | Accepted answer
  
  Not as of [Craft 2.6.2791](https://craftcms.com/changelog#build2791).
  
  If that's a requirement for you, you can not use that tag and put a block in your footer and manually create the script tag with `async defer` set.
  
  > **Comments:**
  > **username_0**: thanks for the feedback username_3 - i'll look in to an alternative way of implementing it.  
  > **username_4**: @username_0 how did you implement this in the end? I am currently at the same conundrum.  
  > **username_0**: @username_4 i think in the end i ended up manually putting it in the footer of my site in an if statement. In this particular site I was setting a title var in each template in twig anyway, and only had a map on one page, so i ended up doing something like {% if title == 'mappage' %}<script src="path/to/script" async defer></script>{% endif %}  
  
  ---
  
  ### Answer by username_1 on 2018-01-15. Score: 8
  
  As of Craft 3 (Tested using [RC5](https://github.com/craftcms/cms/releases/tag/3.0.0-RC5)) you can do it like this:
  
  ```
  {% do view.registerJsFile("path/to/script.js", {"async":"async", "defer":"defer"}) %}
  
  ```
  
  Source: [Documentation for Yii's view.registerJsFile()](http://www.yiiframework.com/doc-2.0/yii-web-view.html#registerJsFile()-detail)
  
  
  ---
  
  ### Answer by username_2 on 2017-07-07. Score: 1
  
  Knowing that `<script>`s are imploded with [\n](https://github.com/craftcms/cms/blob/2.6.2986/src/services/TemplatesService.php#L760) char. You can add async defer this way:
  
  ```
  {%- set scripts = getFootHtml() | split("\n")  -%}
  {%- for script in scripts -%}
      {%- if script matches "%\/assets\/js\/main\.js%" or ' src=' not in script -%}
          {{- script | raw -}}
      {%- else -%}
          {{- script | replace('script type', 'script async defer type') | raw -}}
      {%- endif -%}
  {%- endfor -%}
  
  ```
  
  
  ---
  
  