duilio / pelican-octopress-theme

Octopress default theme copied for pelican
MIT License
149 stars 119 forks source link

Load scripts before plugins that might use them. #83

Open mtstickney opened 8 years ago

mtstickney commented 8 years ago

Body elements are loaded in the order that they are seen; by loading at the end of the body, they are not available for content that needs them, like the github plugin in the sidebar. For the github plugin, this results in a '$ is not defined' error and the repo list is never updated. Moving the scripts to ensures the scripts are loaded before dependent content.

Update: note that this fixes #79.

duilio commented 8 years ago

shouldn't the plugin just wait the dom to be ready in order to have all deps loaded correctly?

mtstickney commented 8 years ago

Not in this case. The github script is already using $.domReady(), but $ hasn't been defined yet, so the handler doesn't even get registered. You'd need to load that script before the plugins in any case (I think that's uh... ender.js, maybe?).

At the very least ender.js should be moved into <head>; moderizr and octopress.js might not technically need it, but it's safe to move them as well, and I don't think there's much downside.

atodorov commented 8 years ago

As far as I can tell the original Octopress theme has these scripts in the section.

mtstickney commented 8 years ago

I think you're mistaken: _include/head.html has modernizr, octopress.js, and ender.js all loaded in <head> (that's the 2.0 tag, the 2.5 branch is the same except they're using jquery instead of ender.js). It's also pretty easy to verify empirically: move the scripts into <head> or above the sidebar include and the plugin works; don't, and it doesn't.

atodorov commented 8 years ago

@mtstickney I meant <head> but wiki escaping failed me :(

mtstickney commented 8 years ago

I see, apologies for misunderstanding (still probably good to have the reference, though).