1

From time to time, I find myself writing server code that produces JavaScript code as the output result.

I can point out why it is really bad:

  • Inextricable tie between server code and client code.
  • Can render client code un-reusable.

But sometimes, it just seems to make sense.

And isn't it kinda sorta interesting?

I guess the question is, is writing server code that produces JavaScript code a really bad practice, or "does everyone do it"?

1 Answer 1

2

It is not necessarily a bad practice, if it makes sense producing JavaScript that way. But with technologies moving more towards richer interfaces that rely more and more on JavaScript I think a good separation between the server and the client side is possible and necessary.

JSON as the exchange format is imho a very good way to achieve this separation. Instead of generating JavaScript that contains data from the server side you just use a lightweight exchange format, that provides all these data. That keeps the client code clean and you don't have to generate any other JavaScript on the server except for the JSON objects (which is really easy in most languages).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.