pros and cons of serverside javascript implementation?

后端 未结 3 1156
半阙折子戏
半阙折子戏 2020-12-07 23:40

I just started experimenting with Aptana Jaxer server side javascript engine for my next project. And i have few quesions about that

  • By using server side JS

3条回答
  •  误落风尘
    2020-12-08 00:12

    As a preface, I use SSJS at my day job. We run a reasonably large (in terms of complexity as well as page views) website on SpiderMonkey. I'll add to Matthew's excellent answer where I have experience.

    Is it really a better approach than using server side languages (assume c#)

    "Better" really depends what you want to do with it. JavaScript itself has some great features, as well as pretty awful ones. If you're serious about developing JS (client or server), I cannot recommend highly enough that you watch Douglas Crockford's presentation, Javascript: The Good Parts if you haven't already. He's done a fantastic job sorting out the cruft, and he's an excellent speaker to boot.

    The biggest thing that I find the SSJS world lacking right now is maturity. I'm not familiar with C#, but JavaScript has no mature standard library, and no mature means of package distribution. To me that's a big piece of the puzzle.

    That said, keep your eye on the CommonJS group. They're working toward defining those exact things. Also, The Jaxer Api Documentation lists the built-ins that are included with that framework.

    how this works well in terms of performance?

    JavaScript itself is not a slow language, nor is it a particularly fast one. As Matthew pointed out, it should be comparable to any other scripting language you would use. The war between the browser vendors to see who can build the fastest browser will benefit the SSJS crowd as well.

    The generational garbage collection that the V8 team build into their engine is a great example of this. Halting the virtual machine to free unreachable objects from the heap and reclaim their memory can be somewhat slow, but they've mitigated that by reducing the amount of objects that need to be inspected when the garbage collector runs.

    how well we can implement & maintain db transactions? can we do that in serverside JS..?

    Jaxer appears to have MySQL and SQLite database APIs. As Matthew mentioned, if you use Rhino, you can use the JDBC api.

    Edit: Added links

提交回复
热议问题