render_sync icon indicating copy to clipboard operation
render_sync copied to clipboard

When I include the javascript files right before the closing body tag, sync is undefined

Open JohnMerlino1 opened this issue 10 years ago • 3 comments

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?

JohnMerlino1 avatar Aug 06 '15 22:08 JohnMerlino1

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.

ajb avatar Feb 06 '16 14:02 ajb

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.

ajb avatar Feb 12 '16 00:02 ajb

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.

psamuel avatar Jun 23 '16 12:06 psamuel