-
-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReactOnRails is not defined when including application.js at bottom of body #71
Comments
@hisapy application.js should be included in the head of the document. Any reason you're placing it in the body? |
Feel free to re-open this ticket if you're sure that there's a case for putting application.js in the body. |
Actually, it seems no there is need anymore to move it out from the head. |
@justin808 Yahoo recommends loading scripts at the bottom of the page to avoid blocking parallel downloads. How do you feel about attaching the components once the JS has loaded? |
@rupurt we did a little research and concluded that the Yahoo advice is no longer worthwhile due to typical caching of the bundled JS file as well as the use of turbolinks. That being said, if you can create a simple demo of a performance gain, we'd be very happy to change the way we're organizing the JS code. |
When including application.js at bottom of body like this:
and using react_component helper to render a component in a view (i.e.: /admin/purchases/new)
I get a Uncaught ReferenceError: ReactOnRails is not defined. Obviously this is because the Javascript written by the helper is executed when the DOM is loading, and before the application.js is included.
In order to avoid the error what I've done is the following:
and in the view:
I just wanted to share my experience using this gem... Is there any better approach for this? If not maybe you'd like to include this strategy in the README.
The text was updated successfully, but these errors were encountered: