Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

jsp

We do a lot of JSP with jQuery/javascript, to make the code more reusable, most of the javascript are thrown to an external library and then import to the jsp file. However, unavoidably some of the values to be used in javascript has to be predefined by java/jsp, that means there is going to have some cases like this

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

I know we can always put such thing as parameters of the function, but it could be very nasty when there is a lot of places like this, make parameter list long and redundant.

So just wondering if it is a good practice just leave the <c:out/> in the javascript file

like image 764
Dreamer Avatar asked Mar 20 '26 00:03

Dreamer


1 Answers

no value 'has to be predefined'. your js code can take data from request, cookies or, the most flexible and powerful way, simply fetch them from server.

you can build fully dynamic one-page-application using only static resources so for sure you don't need this feature. don't make js nor css files dynamic - let clients cache them

like image 121
piotrek Avatar answered Mar 21 '26 12:03

piotrek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!