Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JohnMerlino1 opened this issue Aug 6, 2015 · 3 comments
Milestone

Comments

@JohnMerlino1
Copy link

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?

@ajb
Copy link
Collaborator

ajb commented Feb 6, 2016

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 ajb added the enhancement label Feb 6, 2016
@ajb ajb modified the milestone: 2.0 Feb 12, 2016
@ajb
Copy link
Collaborator

ajb commented Feb 12, 2016

I think there has been some discussion in the past about using HTML comments instead of inline Javascript: #121 (comment)

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.

@psamuel
Copy link

psamuel commented Jun 23, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants