When I include the javascript files right before the closing body tag, sync is undefined
I need to include my assets at the bottom of the page, not in the header, since it will slow down the load of the page. But when I include:
<%= javascript_include_tag Sync.adapter_javascript_url %>
At the bottom of the page (and I assume this needs to be loaded after the application.js is loaded, which is also loaded at the bottom of page, since it itself loads a lot of files)
I get errors when sync tries to access Sync object on the page (since it is not defined yet):
<script type='text/javascript' data-sync-id='/b7c56f83e1dae098e0f8da7b263d4d1a86247672'>
Sync.onReady(function(){
var creator = new Sync.PartialCreator({
name: 'news_feed_activities',
resourceName: 'task',
channel: '/b7c56f83e1dae098e0f8da7b263d4d1a86247672',
selector: '/b7c56f83e1dae098e0f8da7b263d4d1a86247672',
direction: 'append',
refetch: false
});
creator.subscribe();
});
</script>
What options do I have here?
Sorry for the long wait. This seems like a legitimate request, but unfortunately there's not much that can be done about it with the current version of sync.
I think there has been some discussion in the past about using HTML comments instead of inline Javascript: https://github.com/chrismccord/sync/issues/121#issuecomment-42219237
I'd love to see a solution that uses short HTML comments inserted in the markup, that then get "read" by sync's main JS when it's initialized.
Hi. I don't know if this as to do with the issue, but I used RenderSync class instead the Sync class in javascript (or coffeescript) files.