Hacker News new | past | comments | ask | show | jobs | submit login

[deleted]



[meteor dev] This is on us. The docs don't make this point clearly enough. It's also the single most voted for thing on the Meteor 1.0 roadmap: https://trello.com/card/patterns-for-writing-larger-modular-...

JS files in the 'server' directory (or any path with a 'server' component') are not sent to the client.

Everything else is.

Putting code inside an `if (Meteor.isServer)` block doesn't keep it from the client. Now someday we might statically analyze the code for clauses like this and keep them out of the client bundle -- the first step is greenspan's jsparse package -- but not likely in the short term.


This kind of static analysis is really easy to do with falafel:

https://gist.github.com/substack/4735826

Program:

    var falafel = require('falafel');
    var fs = require('fs');
    var src = fs.readFileSync(__dirname + '/src.js', 'utf8');
     
    var output = falafel(src, function (node) {
        if (node.type === 'IfStatement'
        && node.test.type === 'MemberExpression'
        && node.test.object.name === 'Meteor'
        && node.test.property.name === 'isServer') {
            node.update('');
        }
    });
    console.log(output);
Input:

    if (Meteor.isClient) {
        console.log("I'm the client!");
    }
    
    if (Meteor.isServer) {
        console.log("I'm the server!");
    }
Output:

    if (Meteor.isClient) {
        console.log("I'm the client!");
    }
This won't catch fancy things like Meteor['isServer'] or compound expressions but should be a good place to start.

edit: I had them backwards. Fixed now.


That's really, really cool and is definitely a good start.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: