Pregunta

De vez en cuando, me encuentro escribiendo código de servidor que produce código JavaScript como el resultado de la salida.

Me puede señalar por qué es realmente malo:

  • lazo indisoluble que existe entre el código y el código de servidor de cliente.
  • ¿Puede hacer que el código del cliente no-reutilizable.

Pero a veces, que sólo parece tener sentido.

Y no es interesante un poco sorta?

Supongo que la pregunta es, está escribiendo el código de servidor que produce código JavaScript una muy mala práctica, o "qué todo el mundo lo hace"?

¿Fue útil?

Solución

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).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top