Asynchronous JavaScript in production only?

I am trying to load a JavaScript (Angular) application for asynchronous output so that the page can display the loaded image when the browser loads JavaScript later. This works fine in production, but not in development because Sprockets hasn't merged all the files yet.

I am using the following in my HAML file:

= javascript_include_tag "mio", :async => true

      

which works as intended:

<script async="async" src="/assets/mio.js"></script>

      

However, during development, the files are all separate and not executed in order. For example, my Angular request form controller is executed before Angular has finished loading:

<script async="async" src="/assets/angular.js?body=1"></script>
<script async="async" src="/assets/mio.js?body=1"></script>
<script async="async" src="/assets/mio-ng/controllers/quote_form.js?body=1"></script>

      

So the question is, can a javascript_include_tag

flag be ignored async

in development but not in production?

+3


source to share


1 answer


I found a way to tweak this to work, but I believe this is not the best solution:



= javascript_include_tag "application", :async => Rails.env == "production"

      

+5


source







All Articles