Skip to content
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

Fix javascript load order #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

adamgamble
Copy link

Many projects put the javascripts (jquery etc) right before the closing body tag. In this case its good to use content_for :javascripts to yield your inline javascript to the end of the file also so jquery etc is loaded before you try to use them.

@adamgamble
Copy link
Author

My project had its jquery at the bottom of the page, this was causing $ to not be defined in the card partial.

@andrewculver
Copy link
Owner

Hey @adamgamble. Still chewing on this. Trying to figure out if there is a way we can support this without changing the installation instructions, since the Rails default is to link JavaScripts, etc. in the <head> of the layout and I've never had a problem with it, so I'm not inclined to add support for doing it some other way.

Is there some reliable alternative to $(document).ready(...); that will run without jQuery so that it doesn't matter that jQuery isn't loaded yet when the inline JavaScript in the card partial runs?

@gregmolnar
Copy link
Contributor

Is there some reliable alternative to $(document).ready(...); that will run without jQuery so that it doesn't matter that jQuery isn't loaded yet when the inline JavaScript in the card partial runs?

This should do the trick:

window.onload = function() {
  // do something
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants