Skip to content

Commit

Permalink
Use js async
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraichen committed Sep 7, 2017
1 parent bd7d0f5 commit bbd5d56
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions app/assets/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {

import * as components from 'components/index'

document.addEventListener('DOMContentLoaded', () => {
function initalize() {
$('[data-time-ago]').timeago()

document.querySelectorAll('script[data-component]').forEach((el) => {
let component = components[el.dataset.component]
let props = {}
Expand Down Expand Up @@ -38,8 +40,12 @@ document.addEventListener('DOMContentLoaded', () => {

render(createElement(component, props), node)
})
})

jQuery(document).ready(function() {
$('[data-time-ago]').timeago()
})
}

if (document.readyState === "complete" ||
document.readyState === "loaded" ||
document.readyState === "interactive") {
initalize()
} else {
document.addEventListener('DOMContentLoaded', initalize)
}
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ html lang=I18n.locale
link rel="icon" type="images/png" sizes="16x16" href=asset_pack_path('favicon/favicon-16x16.png')
link rel="mask-item" color="#0275d8" href=asset_pack_path('favicon/safari-pinned-tab.svg')
meta name="theme-color" content="#333333"
= javascript_pack_tag 'application'
= javascript_pack_tag 'application', async: true
= stylesheet_pack_tag 'application', media: 'all'
= csrf_meta_tags
body
Expand Down

0 comments on commit bbd5d56

Please sign in to comment.