Is it good practice to include <c: out> in an external javascript file?

We do a lot of JSP with jQuery / javascript to make the code more reusable, most of the javascript is thrown into an external library and then imported into the jsp file. However, inevitably some of the values ​​to be used in javascript must be predefined by java / jsp, which means you will have cases like this

alert('<c:out value="${i18n_alert_msg}"');

      

I know that we can always supply parameters such as function parameters, but it can be very annoying when there are many such places, make the parameter list long and redundant.

So just wondering if this is good practice just leave <c:out/>

in the javascript file

+3


source to share


2 answers


Your front end code needs to be dynamic, not the code file itself, which can cause performance issues.



Create a common / utility (REST / vanilla AJAX) service that will send messages to the client side no matter when needed and call the service from the client as needed.

+1


source


no value "must be predefined". your js code can accept data from a request, a cookie, or, in the most flexible and powerful way, simply fetch it from the server.



you can create a fully dynamic single page application using only static resources so of course you don't need this feature. don't make js or css files dynamic - let clients cache them

+2


source







All Articles