Search code examples
javascriptmeteorreactive-programmingmeteor-blazemeteor-tracker

How can I use Tracker.autorun in a static non-Meteor page?


Some of the pages of my site are server-side rendered so the usual bundle of Meteor JavaScript is not available to them.

We want to keep page size down, but use Tracker.autorun for light-weight reactivity, how can we use this piece of Meteor a-la-carte ?


Solution

  • I have isolated Tracker and all of its dependencies down to a single library you can refer to here: https://s3.amazonaws.com/www.chicagogrooves.com/js/meteor-reactive-packages.js

    This gives you Tracker, ReactiveDict, ReactiveVar, and their dependencies EJSON and Base64 in a single library (41Kb raw unminified, 11Kb gzipped). The only dependency I did not include is UnderscoreJS, as you may want to source that from a CDN.

    Thus, code like this is available to any webpage, even about:blank!

    Tracker.autorun(function() {
      var s = "The name is " + reactiveObject.getName();
      console.log(s);
    });
    

    Have fun exploring with this here Fiddle