Skip to content

Fix javascript load order - #12

Open
adamgamble wants to merge 3 commits into
andrewculver:masterfrom
adamgamble:fix_javascript_load_order
Open

adamgamble wants to merge 3 commits into
andrewculver:masterfrom
adamgamble:fix_javascript_load_order

Conversation

@adamgamble

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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