We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

How to include async or defer in volt syntax?

For example, if I have something like:

{{ javascript_include('third-party/proui/backend/js/vendors/modernizr-respond.min.js') }}

How do I add async or defer into this? I tried , 'async' : true but it didn't work.



51.2k
Accepted
answer

javascript_include has only 2 parameters: source and local (boolean value). Short answer you can't. But:

  1. You can create your own helper by following this steps: https://docs.phalcon.io/en/latest/reference/tags.html#creating-your-own-helpers
  2. Why would you need a javascript async ? There is an interesting discussion about this subject here: https://css-tricks.com/async-attribute-scripts-bottom/

Good luck !

I see. Thanks alot.

javascript_include has only 2 parameters: source and local (boolean value). Short answer you can't. But:

  1. You can create your own helper by following this steps: https://docs.phalcon.io/en/latest/reference/tags.html#creating-your-own-helpers
  2. Why would you need a javascript async ? There is an interesting discussion about this subject here: https://css-tricks.com/async-attribute-scripts-bottom/

Good luck !