0

ほとんどの従来の MVC フレームワークには、独自のテンプレート ソリューション (Jinja2、Mako など) が含まれています。angular や backbone などの新しい ui フレームワークのいずれかを使用することにした場合、それらはフロント エンドのテンプレート ソリューションの使用を奨励しているようです。

性能に違いはありますか?どちらの方法でも良い点と悪い点は何ですか? これらの js テンプレート ソリューションの一部を使用する場合、ie または他のブラウザに問題はありますか?

4

2 に答える 2

1

Depending on the situation, one major factor can be a significant change in bandwidth usage.

For example, my newest project includes the ability to have colour codes in chat (and other places). These codes look like:

`1blue `2green `3yellow `4red `bbold on `Bbold off `b`iBold Italic...

I could parse this server-side and return:

<span style="color:blue">blue </span><span style="color:green">green</span>...

But see how I only did two words and I'm already going longer than the source text! Instead, I chose to implement the parser in JavaScript, on the front-end. This takes a lot of processing off of the server (which would otherwise have to parse this stuff for every single user) to the client (where only one user is being dealt with).

It also had the advantage that I could implement a live preview just by plugging in to the same parser, but that's irrelevant here.

Additionally, client-side templates can be cached, further reducing the amount of data that needs to be sent. This can be particularly beneficial to mobile users, who may not have unlimited data (those poor people... I weep for them... not really)

Personally, given the choice, I'd strongly recommend client-side templating (although in my usual style, I would shun all pre-made solutions and make my own XD I'm weird like that) for a variety of performance reasons. Obviously, the major downside is "no JavaScript = no website", but I'm fine with that since the entire site relies on JS...

于 2014-07-03T16:45:27.537 に答える